Created
August 3, 2015 14:54
-
-
Save yusufcakmak/526ba778654fc95423e2 to your computer and use it in GitHub Desktop.
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; | |
| 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