Java开发网 |
注册 |
登录 |
帮助 |
搜索 |
排行榜 |
发帖统计
|
您没有登录 |
» Java开发网 » Java EE 综合讨论区
打印话题 寄给朋友 订阅主题 |
作者 | Re:初学hibernate 遇到的错误 [Re:zhb] |
zhb
发贴: 9 积分: 0 |
于 2006-09-16 10:33
<?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" > <hibernate-mapping> <!-- Created by the Middlegen Hibernate plugin 2.1 http://boss.bekk.no/boss/middlegen/ http://www.hibernate.org/ --> <class name="org.redsaga.quickstart.Student" table="student" > <id name="id" type="java.lang.Integer" column="id" unsaved-value="0" > <generator class="identity" /> </id> <property name="name" type="java.lang.String" column="name" length="100" /> <!-- Associations --> </class> </hibernate-mapping> import net.sf.hibernate.*; import net.sf.hibernate.cfg.*; import org.dom4j.Attribute; import org.apache.commons.logging.LogFactory; import net.sf.cglib.core.*; import org.redsaga.quickstart.Student; public class Test { public static void main(String[] args) { Session session; try{ Configuration config = new Configuration(); config.addClass(Student.class); SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(); session = sessionFactory.openSession(); Transaction tx = session.beginTransaction(); Student student = new Student(); student.setName("hello"); session.flush(); session.save(student); tx.commit(); //Assert.assertEquals(student.getId().intValue()>0,true); } catch(HibernateException e){ e.printStackTrace(); } } } Java开发规范 |
话题树型展开 |
人气 | 标题 | 作者 | 字数 | 发贴时间 |
11037 | 初学hibernate 遇到的错误 | zhb | 3889 | 2006-09-16 10:31 |
9107 | Re:初学hibernate 遇到的错误 | zhb | 1181 | 2006-09-16 10:31 |
9819 | Re:初学hibernate 遇到的错误 | zhb | 1650 | 2006-09-16 10:33 |
已读帖子 新的帖子 被删除的帖子 |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |