{"id":20504892,"url":"https://github.com/nfriaa/hibernate-tutorial1","last_synced_at":"2025-03-05T20:51:37.161Z","repository":{"id":201889819,"uuid":"105166351","full_name":"nfriaa/hibernate-tutorial1","owner":"nfriaa","description":"Hibernate tutorial 1 : Basic Configuration","archived":false,"fork":false,"pushed_at":"2017-10-18T17:38:58.000Z","size":15,"stargazers_count":0,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-16T07:55:46.990Z","etag":null,"topics":["configuration","hibernate","hibernate5","java","maven","mysql"],"latest_commit_sha":null,"homepage":"","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-09-28T15:34:27.000Z","updated_at":"2017-10-09T15:16:25.000Z","dependencies_parsed_at":null,"dependency_job_id":"ad17dfb8-418c-42ec-9786-12bd002a2533","html_url":"https://github.com/nfriaa/hibernate-tutorial1","commit_stats":null,"previous_names":["nfriaa/hibernate-tutorial1"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nfriaa%2Fhibernate-tutorial1","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nfriaa%2Fhibernate-tutorial1/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nfriaa%2Fhibernate-tutorial1/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nfriaa%2Fhibernate-tutorial1/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nfriaa","download_url":"https://codeload.github.com/nfriaa/hibernate-tutorial1/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242102789,"owners_count":20072142,"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":["configuration","hibernate","hibernate5","java","maven","mysql"],"created_at":"2024-11-15T19:41:04.542Z","updated_at":"2025-03-05T20:51:37.140Z","avatar_url":"https://github.com/nfriaa.png","language":"Java","readme":"# hibernate-tutorial1\nHibernate Basic configuration\n\n[![contributions welcome](https://img.shields.io/badge/contributions-welcome-orange.svg?style=flat)](https://github.com/nfriaa/hibernate-tutorial1/issues) [![Travis](https://img.shields.io/travis/rust-lang/rust.svg)](https://github.com/nfriaa/hibernate-tutorial1) [![license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/nfriaa/hibernate-tutorial1/blob/master/LICENSE)\n\n## Description\nA sample code to configure maven project and test connection to MySQL database and execute some queries using Hibernate.\n* JavaSE 8\n* Hibernate 5\n* Maven 4\n* MySQL 5\n\n## 1. Create database\n```sql\nCREATE DATABASE `persist_db` /*!40100 DEFAULT CHARACTER SET utf8 */\n```\n\n## 2. Create tables\n```sql\nCREATE TABLE `persist_db`.`product` (\n  `id` int(11) NOT NULL AUTO_INCREMENT,\n  `name` varchar(255) DEFAULT NULL,\n  `price` int(11) DEFAULT NULL,\n  PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\n\nCREATE TABLE `persist_db`.`test` (\n  `id` int(11) NOT NULL AUTO_INCREMENT,\n  PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\n```\n\n## 3. Create maven project and add dependencies\n```xml\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```\n\n## 4. Create the hibernate config file '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        \u003cproperty name=\"hibernate.dialect\"\u003eorg.hibernate.dialect.MySQLDialect\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    \u003c/session-factory\u003e\n\u003c/hibernate-configuration\u003e\n```\n\n## 5. Create HibernateUtil.java \nHibernate Utility class with a convenient method to get Session Factory.\n\n## 6. Create main Application class\n* a class whith main method to test connection\n* execute some queries in SQL mode (NativeQuery) : session.createNativeQuery() method\n* select, insert... and read results\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnfriaa%2Fhibernate-tutorial1","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnfriaa%2Fhibernate-tutorial1","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnfriaa%2Fhibernate-tutorial1/lists"}