毕业论文开发语言企业开发JAVA技术.NET技术WEB开发Linux/Unix数据库技术Windows平台移动平台嵌入式论文范文英语论文
您现在的位置: 毕业论文 >> java技术 >> 正文

one-to-one:由映射文件自动生成数据库,添加数据的时候,不能两个一起添加

更新时间:2013-8-3:  来源:毕业论文

one-to-one:由映射文件自动生成数据库,添加数据的时候,不能两个一起添加

one-to-one:由映射文件自动生成数据库,添加数据的时候,不能两个一起添加,相关文件如下:

Idcard.hbm.xml:

Java code?<!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:

Java code?<!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:

Java code?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);


报错:
org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
Caused by: java.sql.BatchUpdateException: ORA-00928: 缺失 SELECT 关键字

用级联呀..

Java code?123456789 Person p1=new Person();             p1.setId(2);             p1.setName("scott1");                            Idcard idcard=new Idcard();             idcard.setValidate(new Date());             idcard.setPerson(p1);                      session.save(idcard);

 

XML/HTML code?<!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" <SPAN style="COLOR: #ff0000">cascade="save-update"</SPAN>/>     </class> </hibernate-mapping>

设为首页 | 联系站长 | 友情链接 | 网站地图 |

copyright©youerw.com 优尔论文网 严禁转载
如果本毕业论文网损害了您的利益或者侵犯了您的权利,请及时联系,我们一定会及时改正。