Idcard.hbm.xml:
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.xyy.domain.Idcard">
<id name="id" type="java.lang.Integer">
<column name="ID" />
<generator class="foreign">
<param name="property">person</param>
</generator>
</id>
<property name="validate" type="java.util.Date">
<column name="validate"/>
</property>
<!-- 配置one-to-one
constrained:不配置,则不会自动生成外键列,配置了,则会生成外键列
-->
<one-to-one name="person" constrained="true"/>
</class>
</hibernate-mapping>
Person.hbm.xml:
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.xyy.domain.Person">
<id name="id" type="java.lang.Integer">
<column name="ID" />
<generator class="assigned"/>
</id>
<property name="name" type="java.lang.String">
<column name="name"/>
</property>
<!-- 配置one-to-one -->
<one-to-one name="idcard" />
</class>
</hibernate-mapping>
TestMain.java:
Person p1=new Person();
p1.setId(2);
p1.setName("scott1");
Idcard idcard=new Idcard();
idcard.setValidate(new Date());
idcard.setPerson(p1);
session.save(p1);
session.save(idcard);
error:
org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
Caused by: java.sql.BatchUpdateException: ORA-00928: missing SELECT keyword
---- - Solution --------------------------------------------
+1
------ For reference only -------------------------------- -------
session.save (p1);
Idcard idcard = new Idcard ();
idcard.setValidate (new Date ());
idcard.setPerson (p1);
Try this happen !
p1 is a temporary state , first persistence it !
------ For reference only ---------------------------------- -----
error is still the same
------ For reference only ----------------------- ----------------
with cascading ah ..
Person p1=new Person();
p1.setId(2);
p1.setName("scott1");
Idcard idcard=new Idcard();
idcard.setValidate(new Date());
idcard.setPerson(p1);
session.save(idcard);
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.xyy.domain.Idcard">
<id name="id" type="java.lang.Integer">
<column name="ID" />
<generator class="foreign">
<param name="property">person</param>
</generator>
</id>
<property name="validate" type="java.util.Date">
<column name="validate"/>
</property>
<!-- 配置one-to-one
constrained:不配置,则不会自动生成外键列,配置了,则会生成外键列
-->
<one-to-one name="person" constrained="true" cascade="save-update"/>
</class>
</hibernate-mapping>
------ For reference only ----------------------------------- ----
no use ah , this problem usually where to start to solve ?
------ For reference only -------------------------------------- -
plus cascade operation on the line
cascade = save-update
------ For reference only ----------------------------- ----------
I have encountered this problem , how to solve ? ? ?
------ For reference only -------------------------------------- -
upstairs to answer all are crap , are not right.
I solved this problem
landlord Idcard.hbm.xml configuration file contains this line :
which validate is a keyword that will validate the other can be changed , such as what validate1 and the like.
------ For reference only -------------------------------------- -
This is the real answer , ah, very grateful
没有评论:
发表评论