奇怪的Hibernate问题,不能保存,无异常,无insert语句,但是对象UUID已产生。

Abib 2009-01-16 10:29:14
大家帮我看看,给点提示,先谢谢了!

Hibernate version:
3.2.3.ga

Mapping documents:

<hibernate-mapping package="objects">
<class name="OrganizationStructureObject" abstract="true">
<id name="objID">
<generator class="uuid.hex"></generator>
</id>
<property name="clientID" not-null="true"></property>
<property name="name" not-null="true"></property>
<property name="abbreviation" type="string" length="20"></property>
<property name="description"></property>
<property name="typeCode" not-null="true"></property>
<union-subclass name="OrganizationUnit" table="TA_ORG_ORG_UNIT">
</union-subclass>
<union-subclass name="Person" table="TA_ORG_PERSON">
<property name="userID"></property>
</union-subclass>
</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
s.save(object);

Name and version of the database you are using:
MySQL 5.

The generated SQL (show_sql=true):
No SQL genernated.

Debug level Hibernate log excerpt:

Nothing


not a transcation issue because other objects are saved correctly. Only objects within <union-subclass> were wrong.
After save(), the UUID was created correctly. But the objects were not saved into database. NO SQL output, no any other debug level info from hibernate.

Thanks a lot for your help.
...全文
184 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
cxalxpks 2009-03-13
  • 打赏
  • 举报
回复
学习下。
Landor2004 2009-03-13
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 Abib 的回复:]
关于事务,已经在config里面设为自动提交:

<property name="hibernate.connection.autocommit">true </property>

我觉得问题的关键在于,insert记录的SQL语句为什么没有生成?其它的sql语句都从控制台输出了,就这两个Object不行。
[/Quote]

设置了autocommit是true,那么在save操作之后必须要再调用session.flush();
Yanbin_Q 2009-01-18
  • 打赏
  • 举报
回复
出异常,也许屏蔽了异常

Hibernate 在插入记录之前会产生相应的ID,再执行 insert,所以生成了id,没有记录也不奇怪。
Jermaine 2009-01-17
  • 打赏
  • 举报
回复
你的数据库里面是不是已经有了一个id相同的对象了?如果hibernate缓存里已经有这个对象,那么再save的时候将不会产生Sql语句了
Alien 2009-01-16
  • 打赏
  • 举报
回复
不太明白,不过帮你顶一下
my_cheating 2009-01-16
  • 打赏
  • 举报
回复
应该是自动提交了的
Abib 2009-01-16
  • 打赏
  • 举报
回复
关于事务,已经在config里面设为自动提交:

<property name="hibernate.connection.autocommit">true</property>

我觉得问题的关键在于,insert记录的SQL语句为什么没有生成?其它的sql语句都从控制台输出了,就这两个Object不行。
zou_wei_forever 2009-01-16
  • 打赏
  • 举报
回复
没开启事务?这样试试:
Transaction tx = s.beginTransactioin();
s.save(object);
tx.commit();
jeseph 2009-01-16
  • 打赏
  • 举报
回复
关注

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧