Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

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