论坛首页 Java企业应用论坛

执行正常,但没有在数据库中生成记录,怎么回事啊?谢谢

浏览 4601 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2003-09-27  
执行过程中没有异常,而且我用new SchemaExport(cfg).create(true,true);在数据库生成了表
但添加对象却无法生成记录,请问是什么原因?谢谢
附代码:
public void run() throws Exception{
    Configuration cfg  = new Configuration().addClass    (Contact.class);
    SessionFactory sessionFactory = cfg.buildSessionFactory();
    //new SchemaExport(cfg).create(true,true);

    Session session = sessionFactory.openSession();

    Contact contact = new Contact("Albert Lee");
    contact.setEmail("abc@263.net");
    contact.setTel("1369354324");

    session.save(contact);
    session.flush();
    //session.
    session.close();
  }
   发表时间:2003-09-27  
你用的什么数据库啊??

我用interbase/firebird遇到这个问题

http://forum.hibernate.org.cn/viewtopic.php?t=565

1firebird必须用事务:

Transaction tx = session.beginTransaction(); ////*

User user = new User("sc433");
user.setMail("sc433@srereere");
session.save(user);



session.flush();

tx.commit(); ////////*
session.close();

hibernate.transaction.factory_class net.sf.hibernate.transaction.JDBCTransactionFactory

如果没有使用事务,那么session.close()时就自动回滚了。。。
interbase的事务是王八蛋,在delphi中把我搞的太辛苦。在java中也是这么样。


在console中,输出的都是
[java] Hibernate: insert into USER_T (E_MAIL, USER_ID) values (?, ?)
但是输入到数据库中的是字符。。。
真是shit。。。。



2
java object的 primary key如果是string的话
那么hibernate自动生成的表,响应字段默认有255这么长,
但是interbase要求index不能太长,只能手工改,真是shit
0 请登录后投票
   发表时间:2003-09-27  
我用的oracle数据库阿
谢谢
0 请登录后投票
   发表时间:2003-09-27  
把你的控制台的输出贴出来看看撒
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics