求助各位大神:一对一,Hibernate 下正常,但是SSH下只能保存主表信息。
本帖最后由 u011327966 于 2013-12-10 10:11:20 编辑
大神,求助啊,从昨天一直整到现在,就是没找出错误!!!小弟在此表示感谢!
建表:
CREATE TABLE t_person
(
id INT PRIMARY KEY AUTO_INCREMENT,
userName VARCHAR(30)
)
CREATE TABLE t_card
(
id INT PRIMARY KEY ,
cardNum VARCHAR(30),
FOREIGN KEY(id) REFERENCES t_person(id)
)
实体类:
package com.lp.entity;
public class Person
{
private int id;
private String userName ;
private Card card;
public int getId()
{
return id;
}
public void setId(int id)
{
this.id = id;
}
public String getUserName()
{
return userName;
}
public void setUserName(String userName)
{
this.userName = userName;
}
public Card getCard()
{
return card;
}
public void setCard(Card card)
{
this.card = card;
}
}
package com.lp.entity;
public class Card
{
private int id;
private String cardNum;
private Person person ;
public int getId()
{
return id;
}
public void setId(int id)
{
this.id = id;
}
public String getCardNum()
{
return cardNum;
}
public void setCardNum(String cardNum)
{
this.cardNum = cardNum;
}
public Person getPerson()
{
return person;
}
public void setPerson(Person person)
{
this.person = person;
}
}
映射文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.lp.entity">
<class name="Person" table="t_person">
<id name="id">
<generator class="native" ></generator>
</id>
<property name="userName"></property >
<one-to-one name="card" class="Card"></one-to-one>
</class>
</hibernate-mapping>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.lp.entity">
<class name="Card" table="t_card">
<id name="id" column ="id">
<generator class="foreign">
<param name="property">person</param>
</generator>
<