This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package co.mobiwise.hibernate.main; | |
| /** | |
| * Created by yusufcakmak on 8/3/15. | |
| */ | |
| import java.util.Date; | |
| import org.hibernate.Session; | |
| import co.mobiwise.hibernate.model.Book; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package co.mobiwise.hibernate.main; | |
| /** | |
| * Created by yusufcakmak on 8/3/15. | |
| */ | |
| import java.util.Date; | |
| import co.mobiwise.hibernate.model.Book1; | |
| import org.hibernate.Session; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package co.mobiwise.hibernate.main; | |
| import co.mobiwise.hibernate.model.Book1; | |
| import co.mobiwise.hibernate.util.HibernateUtil; | |
| import org.hibernate.Session; | |
| import org.hibernate.SessionFactory; | |
| import java.util.Date; | |
| /** |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
| <modelVersion>4.0.0</modelVersion> | |
| <groupId>co.mobiwise</groupId> | |
| <artifactId>hibernatecrud</artifactId> | |
| <version>1.0-SNAPSHOT</version> | |
| <packaging>jar</packaging> | |
| <name>hibernatecrud</name> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package co.mobiwise.hibernate.app; | |
| import co.mobiwise.hibernate.model.Book; | |
| import co.mobiwise.hibernate.util.HibernateUtil; | |
| import org.hibernate.Session; | |
| import java.util.ArrayList; | |
| public class App | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="utf-8"?> | |
| <!DOCTYPE hibernate-configuration PUBLIC | |
| "-//Hibernate/Hibernate Configuration DTD 3.0//EN" | |
| "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> | |
| <hibernate-configuration> | |
| <session-factory> | |
| <property name="connection.url">jdbc:mysql://localhost:3306/book</property> | |
| <property name="connection.username">root</property> | |
| <property name="connection.password"></property> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package co.mobiwise.hibernate.util; | |
| /** | |
| * Created by yusufcakmak on 8/4/15. | |
| */ | |
| import org.hibernate.SessionFactory; | |
| import org.hibernate.cfg.Configuration; | |
| public class HibernateUtil { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package co.mobiwise.hibernate.model; | |
| import javax.annotation.Generated; | |
| import javax.persistence.*; | |
| /** | |
| * Created by yusufcakmak on 8/4/15. | |
| */ | |
| @Entity | |
| @Table(name="book") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public void saveBook(Book book) { | |
| Session session = HibernateUtil.getSessionFactory().openSession(); | |
| session.beginTransaction(); | |
| session.save(book); | |
| session.getTransaction().commit(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public void updateBook(Book book){ | |
| Session session = HibernateUtil.getSessionFactory().openSession(); | |
| session.beginTransaction(); | |
| session.merge(book); | |
| session.getTransaction(); | |
| } |