a question to use &lt;any&gt; tag<br><br><br>&nbsp;&nbsp;<br> Hibernate version:&nbsp;&nbsp;<br> 3.0 <br> Mapping documents: <br>&nbsp;&nbsp;<br> &lt;?xml version=&quot;1.0&quot;?&gt; <br> &lt;!DOCTYPE hibernate-mapping PUBLIC &quot;-//Hibernate/Hibernate Mapping DTD//EN&quot; 
<br>         &quot;<a href="http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd</a>&quot;&gt; <br> &lt;hibernate-mapping package=&quot;com.crazyasp.testany&quot;&gt; 
<br>         &lt;class name=&quot;TestAnyA&quot; table=&quot;TestAnyA&quot; polymorphism=&quot;implicit&quot;&gt; <br>                 &lt;id name=&quot;id&quot; type=&quot;integer&quot; column=&quot;id&quot;&gt; <br>                         &lt;generator class=&quot;native&quot;/&gt; 
<br>                 &lt;/id&gt; <br>                 &lt;set name=&quot;c&quot; inverse=&quot;true&quot;&gt; <br>                         &lt;key&gt; <br>                                 &lt;column name=&quot;ownerId&quot;/&gt; <br>                         &lt;/key&gt; <br>                         &lt;one-to-many class=&quot;com.crazyasp.testany.TestAnyC
&quot;/&gt; <br>                 &lt;/set&gt; <br>         &lt;/class&gt; <br> &lt;/hibernate-mapping&gt; <br>&nbsp;&nbsp;<br> &lt;?xml version=&quot;1.0&quot;?&gt; <br> &lt;!DOCTYPE hibernate-mapping PUBLIC &quot;-//Hibernate/Hibernate Mapping DTD//EN&quot; 
<br>         &quot;<a href="http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd</a>&quot;&gt; <br> &lt;hibernate-mapping package=&quot;com.crazyasp.testany&quot;&gt; 
<br>         &lt;class name=&quot;TestAnyB&quot; table=&quot;TestAnyB&quot; polymorphism=&quot;implicit&quot;&gt; <br>                 &lt;id name=&quot;id&quot; type=&quot;integer&quot; column=&quot;id&quot;&gt; <br>                         &lt;generator class=&quot;native&quot;/&gt; 
<br>                 &lt;/id&gt;                 <br>                 &lt;set name=&quot;c&quot; cascade=&quot;delete&quot; inverse=&quot;true&quot;&gt; <br>                         &lt;key&gt; <br>                                 &lt;column name=&quot;ownerId&quot;/&gt; <br>                         &lt;/key&gt; <br>                         &lt;one-to-many class=&quot;
com.crazyasp.testany.TestAnyC&quot;/&gt; <br>                 &lt;/set&gt; <br>         &lt;/class&gt; <br> &lt;/hibernate-mapping&gt; <br>&nbsp;&nbsp;<br> &lt;?xml version=&quot;1.0&quot;?&gt; <br> &lt;!DOCTYPE hibernate-mapping PUBLIC &quot;-//Hibernate/Hibernate Mapping DTD//EN&quot; 
<br>         &quot;<a href="http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd</a>&quot;&gt; <br> &lt;hibernate-mapping package=&quot;com.crazyasp.testany&quot;&gt; 
<br>         &lt;class name=&quot;TestAnyC&quot; table=&quot;TestAnyC&quot; polymorphism=&quot;implicit&quot;&gt; <br>                 &lt;id name=&quot;id&quot; type=&quot;integer&quot; column=&quot;id&quot;&gt; <br>                         &lt;generator class=&quot;native&quot;/&gt; 
<br>                 &lt;/id&gt; <br>                 &lt;any name=&quot;owner&quot; meta-type=&quot;string&quot; id-type=&quot;integer&quot;&gt; <br>                         &lt;meta-value value=&quot;a&quot; class=&quot;com.crazyasp.testany.TestAnyA&quot;/&gt; <br>                         &lt;meta-value value=&quot;b&quot; class=&quot;
com.crazyasp.testany.TestAnyB&quot;/&gt; <br>                         &lt;column name=&quot;ownerType&quot;/&gt; <br>                         &lt;column name=&quot;ownerId&quot; not-null=&quot;false&quot;/&gt; <br>                 &lt;/any&gt; <br>         &lt;/class&gt; <br> &lt;/hibernate-mapping&gt; 
<br>&nbsp;&nbsp;<br>&nbsp;&nbsp;<br> Code between sessionFactory.openSession() and session.close(): <br>&nbsp;&nbsp;<br> Full stack trace of any exception that occurs: <br>&nbsp;&nbsp;<br> Name and version of the database you are using: <br> postgresql 8.0 <br>
 The generated SQL (show_sql=true): <br> Hibernate: select nextval (&#39;hibernate_sequence&#39;) <br> Hibernate: insert into TestAnyC (ownerType, ownerId, id) values (?, ?, ?) <br> Debug level Hibernate log excerpt: <br>
&nbsp;&nbsp;<br> 2007-03-23 10:48:53,603 [main] WARN&nbsp;&nbsp;org.hibernate.util.JDBCExceptionReporter - SQL Error: 0, SQLState: null <br> 2007-03-23 10:48:53,605 [main] ERROR org.hibernate.util.JDBCExceptionReporter - 批次处理0insert into TestAnyC (ownerType, ownerId, id) values (a, 1, 3)失败,调用getNextException查看原因。 
<br> 2007-03-23 10:48:53,606 [main] WARN&nbsp;&nbsp;org.hibernate.util.JDBCExceptionReporter - SQL Error: 0, SQLState: 23503 <br>2007-03-23 10:48:53,607 [main] ERROR org.hibernate.util.JDBCExceptionReporter - 错误: 插入或更新表 &quot;testanyc&quot; 违反外键约束 &quot;fkbf7747a9ff594b5e&quot; 
<br>&nbsp;&nbsp; Detail: Key (ownerid)=(1) is not present in table &quot;testanyb&quot;. <br>2007-03-23 10:48:53,633 [main] ERROR org.hibernate.event.def.AbstractFlushingEventListener - Could not synchronize database state with session 
<br> org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update