Created
August 3, 2015 14:53
-
-
Save yusufcakmak/bacc7675decc390c2f15 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 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