⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 idincrementexample.java

📁 Hibernate Doc Tut .You will learn how to use and create a simple Hibernate examples.
💻 JAVA
字号:
/**
 * @author Deepak Kumar
 *
 * http://www.roseindia.net
 * Example to show the increment class of hibernate generator element to 
 * automatically generate the primay key
 */
package roseindia.tutorial.hibernate;

//Hibernate Imports
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;


public class IdIncrementExample {
	public static void main(String[] args) {
		Session session = null;

		try{
			// This step will read hibernate.cfg.xml and prepare hibernate for use
			SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
			session =sessionFactory.openSession();
			 
			org.hibernate.Transaction tx = session.beginTransaction();
			 
			//Create new instance of Contact and set values in it by reading them from form object
		 	System.out.println("Inserting Book object into database..");
			Book book = new Book();
			book.setStrBookName("Hibernate Tutorial");
			session.save(book);
			System.out.println("Book object persisted to the database.");
	        tx.commit();
	        session.flush();
	        session.close();
		}catch(Exception e){
			System.out.println(e.getMessage());
		}finally{
			}
		
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -