{"id":20504881,"url":"https://github.com/nfriaa/hibernate-tutorial3","last_synced_at":"2025-07-16T02:33:56.291Z","repository":{"id":201889821,"uuid":"105593887","full_name":"nfriaa/hibernate-tutorial3","owner":"nfriaa","description":"Hibernate tutorial 3 : Hibernate Annotations","archived":false,"fork":false,"pushed_at":"2017-10-18T17:40:29.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-16T07:55:46.303Z","etag":null,"topics":["annotations","hibernate","hibernate-annotations","hibernate5","java","maven","mysql"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nfriaa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2017-10-02T23:02:37.000Z","updated_at":"2017-10-04T18:02:13.000Z","dependencies_parsed_at":null,"dependency_job_id":"c83f2789-25a7-446e-998a-9596b162608d","html_url":"https://github.com/nfriaa/hibernate-tutorial3","commit_stats":null,"previous_names":["nfriaa/hibernate-tutorial3"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nfriaa%2Fhibernate-tutorial3","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nfriaa%2Fhibernate-tutorial3/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nfriaa%2Fhibernate-tutorial3/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nfriaa%2Fhibernate-tutorial3/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nfriaa","download_url":"https://codeload.github.com/nfriaa/hibernate-tutorial3/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242102785,"owners_count":20072140,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["annotations","hibernate","hibernate-annotations","hibernate5","java","maven","mysql"],"created_at":"2024-11-15T19:41:02.516Z","updated_at":"2025-03-05T20:51:36.522Z","avatar_url":"https://github.com/nfriaa.png","language":"Java","readme":"# hibernate-tutorial3\nHibernate Annotations\n\n[![contributions welcome](https://img.shields.io/badge/contributions-welcome-orange.svg?style=flat)](https://github.com/nfriaa/hibernate-tutorial3/issues) [![Travis](https://img.shields.io/travis/rust-lang/rust.svg)](https://github.com/nfriaa/hibernate-tutorial3) [![license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/nfriaa/hibernate-tutorial3/blob/master/LICENSE)\n\n## Description\nA sample code to use Hibernate in **Annotations** mode\n* JavaSE 8\n* Hibernate 5 / Annotations\n* Maven 4\n* MySQL 5\n\n## 1. Database (the same in Tutorial 2)\nWe will use the same database / table\n\n## 2. Maven \"pom.xml\" dependencies\n```xml\n\u003cdependencies\u003e\n    \u003c!-- MySQL connector --\u003e\n    \u003cdependency\u003e\n        \u003cgroupId\u003emysql\u003c/groupId\u003e\n        \u003cartifactId\u003emysql-connector-java\u003c/artifactId\u003e\n        \u003cversion\u003e6.0.6\u003c/version\u003e\n    \u003c/dependency\u003e\n    \u003c!-- Hibernate --\u003e\n    \u003cdependency\u003e\n        \u003cgroupId\u003eorg.hibernate\u003c/groupId\u003e\n        \u003cartifactId\u003ehibernate-core\u003c/artifactId\u003e\n        \u003cversion\u003e5.2.11.Final\u003c/version\u003e\n    \u003c/dependency\u003e\n\u003c/dependencies\u003e\n```\n\n## 3. Changes in \"hibernate.cfg.xml\"\n```xml\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003c!DOCTYPE hibernate-configuration PUBLIC \"-//Hibernate/Hibernate Configuration DTD 3.0//EN\" \"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd\"\u003e\n\u003chibernate-configuration\u003e\n    \u003csession-factory\u003e\n        \u003c!-- MySQL --\u003e\n        \u003cproperty name=\"hibernate.dialect\"\u003eorg.hibernate.dialect.MySQL5InnoDBDialect\u003c/property\u003e\n        \u003cproperty name=\"hibernate.connection.url\"\u003ejdbc:mysql://localhost:3306/persist_db?useTimezone=true\u0026amp;serverTimezone=UTC\u003c/property\u003e\n        \u003cproperty name=\"hibernate.connection.username\"\u003eroot\u003c/property\u003e\n        \u003cproperty name=\"hibernate.connection.password\"\u003e\u003c/property\u003e\n\n        \u003c!-- Hibernate --\u003e\n        \u003cproperty name=\"show_sql\"\u003etrue\u003c/property\u003e\n        \u003cproperty name=\"format_sql\"\u003efalse\u003c/property\u003e\n        \u003cproperty name=\"hibernate.hbm2ddl.auto\"\u003eupdate\u003c/property\u003e\n\n        \u003c!-- Entities --\u003e\n        \u003cmapping class=\"net.isetjb.hibernatetutorial3.Product\"/\u003e\n    \u003c/session-factory\u003e\n\u003c/hibernate-configuration\u003e\n```\n* hibernate.hbm2ddl.auto : update =\u003e update the database schema with defined entities\n* hibernate.hbm2ddl.auto : create =\u003e creates the schema necessary for defined entities, destroying any previous data\n\n## 3. No \"Product.hbm.xml\" file\nThere is no \"Product.hbm.xml\" mapping file. To do mapping we will use Hibernate **Annotations** instead\n\n## 4. Annotations in POJO classes \"Product.java\"\n```java\nimport javax.persistence.Column;\nimport javax.persistence.Entity;\nimport javax.persistence.GeneratedValue;\nimport javax.persistence.GenerationType;\nimport javax.persistence.Id;\nimport javax.persistence.Table;\n\n@Entity\n@Table(name = \"product\")\npublic class Product\n{\n    @Id\n    @GeneratedValue(strategy = GenerationType.IDENTITY)\n    @Column(name = \"id\", nullable = false)\n    private int id;\n\n    @Column(name = \"name\", length = 255, nullable = true)\n    private String name;\n\n    @Column(name = \"price\", nullable = true)\n    private int price;\n\n    // GETTERs and SETTERs here...\n}\n```\n* @Entity : link to the \"Product\" class (Bean / POJO)\n* @Table : table that will be used to persist the entity in the database\n* @Id : primary key\n* @GeneratedValue : generation type for the primary key (ex : AUTO_INCREMENT in MySQL)\n* @Column : details of the column to which a property will be mapped\n\n## 5. Class \"Application.java\"\nUse exactly \"Application.java\" in Tutorial 2 to test","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnfriaa%2Fhibernate-tutorial3","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnfriaa%2Fhibernate-tutorial3","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnfriaa%2Fhibernate-tutorial3/lists"}