[hibernate-announce] a question to use <any> tag

Samael Cui crazyasp at gmail.com
Mon Mar 26 00:11:10 EDT 2007


a question to use <any> tag



Hibernate version:
3.0
Mapping documents:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.crazyasp.testany">
<class name="TestAnyA" table="TestAnyA" polymorphism="implicit">
<id name="id" type="integer" column="id">
<generator class="native"/>
</id>
<set name="c" inverse="true">
<key>
<column name="ownerId"/>
</key>
<one-to-many class="com.crazyasp.testany.TestAnyC"/>
</set>
</class>
</hibernate-mapping>

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.crazyasp.testany">
<class name="TestAnyB" table="TestAnyB" polymorphism="implicit">
<id name="id" type="integer" column="id">
<generator class="native"/>
</id>
<set name="c" cascade="delete" inverse="true">
<key>
<column name="ownerId"/>
</key>
<one-to-many class="com.crazyasp.testany.TestAnyC"/>
</set>
</class>
</hibernate-mapping>

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.crazyasp.testany">
<class name="TestAnyC" table="TestAnyC" polymorphism="implicit">
<id name="id" type="integer" column="id">
<generator class="native"/>
</id>
<any name="owner" meta-type="string" id-type="integer">
<meta-value value="a" class="com.crazyasp.testany.TestAnyA"/>
<meta-value value="b" class="com.crazyasp.testany.TestAnyB"/>
<column name="ownerType"/>
<column name="ownerId" not-null="false"/>
</any>
</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:
postgresql 8.0
The generated SQL (show_sql=true):
Hibernate: select nextval ('hibernate_sequence')
Hibernate: insert into TestAnyC (ownerType, ownerId, id) values (?, ?, ?)
Debug level Hibernate log excerpt:

2007-03-23 10:48:53,603 [main] WARN
org.hibernate.util.JDBCExceptionReporter - SQL Error: 0, SQLState: null
2007-03-23 10:48:53,605 [main] ERROR
org.hibernate.util.JDBCExceptionReporter - 批次处理0insert into TestAnyC
(ownerType, ownerId, id) values (a, 1, 3)失败,调用getNextException查看原因。
2007-03-23 10:48:53,606 [main] WARN
org.hibernate.util.JDBCExceptionReporter - SQL Error: 0, SQLState: 23503
2007-03-23 10:48:53,607 [main] ERROR
org.hibernate.util.JDBCExceptionReporter - 错误: 插入或更新表 "testanyc" 违反外键约束
"fkbf7747a9ff594b5e"
   Detail: Key (ownerid)=(1) is not present in table "testanyb".
2007-03-23 10:48:53,633 [main] ERROR
org.hibernate.event.def.AbstractFlushingEventListener - Could not
synchronize database state with session
org.hibernate.exception.ConstraintViolationException: Could not execute JDBC
batch update
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/hibernate-announce/attachments/20070326/ef59bb8e/attachment.html 


More information about the hibernate-announce mailing list