Skip to content

Instantly share code, notes, and snippets.

@yusufcakmak
Created August 3, 2015 14:53
Show Gist options
  • Select an option

  • Save yusufcakmak/bacc7675decc390c2f15 to your computer and use it in GitHub Desktop.

Select an option

Save yusufcakmak/bacc7675decc390c2f15 to your computer and use it in GitHub Desktop.
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;
import co.mobiwise.hibernate.util.HibernateUtil;
public class HibernateMain {
public static void main(String[] args) {
Book book = new Book();
book.setBookName("Akıl Oyunları");
book.setBookDesc("Beyninizi 31 Günde Yeniden Keşfedin");
book.setInsertTime(new Date());
//Get Session
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
//start transaction
session.beginTransaction();
//Save the Model object
session.save(book);
//Commit transaction
session.getTransaction().commit();
System.out.println("Book ID="+book.getId());
//terminate session factory, otherwise program won't end
HibernateUtil.getSessionFactory().close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment