Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save yusufcakmak/0b507ef47822f6fd9d13 to your computer and use it in GitHub Desktop.
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;
/**
* Created by yusufcakmak on 8/3/15.
*/
public class HibernateJavaConfigMain {
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.getSessionJavaConfigFactory();
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