• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

An hibernate error about one-to-one

 
Zhao Yutong
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i do a test one-to-one program in hibernate ,but when i run ,
there is an error occur,
about the program :
in database ,i hava two table,Person and Idcard,
Person.hbm.xml
<class name="site.factory.Person" table="person" schema="dbo">
<id name="personid" type="java.lang.Integer">
<column name="personid" />
<generator class="native" />
</id>
<property name="name" type="java.lang.String">
<column name="name" length="50" />
</property>
<property name="age" type="java.lang.Integer">
<column name="age" />
</property>
<one-to-one name="idcard" class="site.factory.Idcard" cascade="all"/>
</class>


Idcard.hbm.xml

<class name="site.factory.Idcard" table="idcard" schema="dbo" >
<id name="idcardid" type="java.lang.Integer">
<column name="idcardid" />
<generator class="foreign" >
<param name="property">person</param>
</generator>
</id>
<property name="idcardnum" type="java.lang.String">
<column name="idcardnum" length="50" />
</property>
<one-to-one name="person" class="site.factory.Person"></one-to-one>
</class>


in Person.hbm.xml and Idcard.hbm.xml ,i hava do one-to-one mapping ,

Person person=new Person();
person.setName("zhaoyta");
person.setAge(new Integer(43));
Idcard card=new Idcard();
card.setIdcardnum("4983902481902");
person.setIdcard(card);
PersonDAO dao=new PersonDAO();
dao.addPerson(person);
that is my testcase ,

can you help me ,very thank you
 
Zhao Yutong
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the problem have be solved ;

Person person=new Person();
person.setName("zhaoyta");
person.setAge(new Integer(43));
Idcard card=new Idcard();
card.setIdcardnum("4983902481902");
person.setIdcard(card);

card.setPerson(person);//here must be write,one anthor set

PersonDAO dao=new PersonDAO();
dao.addPerson(person);
 
Rashid Darvesh
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi have a look at these use cases this mighht help

http://www.makemyinfo.com/Tutorial.do?action=getTutorial&tutId=T0005.jsp
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic