Skip to content

Instantly share code, notes, and snippets.

View yusufcakmak's full-sized avatar
🏠
Working from home

Yusuf Cakmak yusufcakmak

🏠
Working from home
View GitHub Profile
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;
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;
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;
/**
@yusufcakmak
yusufcakmak / pom.xml
Created August 4, 2015 12:35
HibernateCRUDExample
<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>
@yusufcakmak
yusufcakmak / App.java
Created August 4, 2015 13:16
HibernateCrudExample
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
{
@yusufcakmak
yusufcakmak / hibernate.cfg.xml
Created August 4, 2015 13:18
HibernateCRUDExample
<?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>
@yusufcakmak
yusufcakmak / HibernateUtil.java
Created August 4, 2015 13:19
HibernateCRUDExample
package co.mobiwise.hibernate.util;
/**
* Created by yusufcakmak on 8/4/15.
*/
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class HibernateUtil {
@yusufcakmak
yusufcakmak / Book.java
Created August 4, 2015 13:24
HibernateCRUDExample
package co.mobiwise.hibernate.model;
import javax.annotation.Generated;
import javax.persistence.*;
/**
* Created by yusufcakmak on 8/4/15.
*/
@Entity
@Table(name="book")
@yusufcakmak
yusufcakmak / Create
Last active August 29, 2015 14:26
HibernateCRUDExample
public void saveBook(Book book) {
Session session = HibernateUtil.getSessionFactory().openSession();
session.beginTransaction();
session.save(book);
session.getTransaction().commit();
}
public void updateBook(Book book){
Session session = HibernateUtil.getSessionFactory().openSession();
session.beginTransaction();
session.merge(book);
session.getTransaction();
}