首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

Hibernate 运用 Annotation 2(主键生成方式)

2012-09-21 
Hibernate 使用 Annotation 2(主键生成方式)hibernate.cfg.xml配置文件:?JleeTest.java代码:package com.j

Hibernate 使用 Annotation 2(主键生成方式)

hibernate.cfg.xml配置文件:

?

JleeTest.java代码:

package com.jlee02.createId;import junit.framework.TestCase;import org.hibernate.Session;import org.hibernate.SessionFactory;import org.hibernate.cfg.AnnotationConfiguration;import org.hibernate.tool.hbm2ddl.SchemaExport;public class JleeTest extends TestCase {public void testJlee(){SessionFactory sf = new AnnotationConfiguration().configure().buildSessionFactory() ;Session session = sf.getCurrentSession() ;session.beginTransaction() ;Jlee jlee = new Jlee() ;jlee.setName("JLee") ;jlee.setAge(23) ;jlee.setPhone("12123123123") ;session.save(jlee) ;session.getTransaction().commit() ;}//相当于hbm2ddl 设为 createpublic void testExport(){new SchemaExport(new AnnotationConfiguration().configure()).create(false, true) ;}}

?

热点排行