hibernate中一对一param named "property" is required for foreign id generation strategy错误

两个类Person、IdCard

Person:主键id

	private Integer id;
	private String name;
	private IdCard idCard;
IdCard:主键id 外键id (此处的id即为Person里面的id)

	private Integer id;
	private Person person;
	private Date usefulLife;
出现错误:

org.hibernate.MappingException: could not instantiate id generator [entity-name=cn.itcast.hibernate.domain.IdCard]
at org.hibernate.id.IdentifierGeneratorFactory.create(IdentifierGeneratorFactory.java:109)
at org.hibernate.mapping.SimpleValue.createIdentifierGenerator(SimpleValue.java:152)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:197)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1313)
at cn.itcast.hibernate.HibernateSessionFactory.<clinit>(HibernateSessionFactory.java:31)
at cn.itcast.hibernate.One2One.add(One2One.java:25)
at cn.itcast.hibernate.One2One.main(One2One.java:18)
Caused by: org.hibernate.MappingException: param named "property" is required for foreign id generation strategy
at org.hibernate.id.ForeignGenerator.configure(ForeignGenerator.java:82)
at org.hibernate.id.IdentifierGeneratorFactory.create(IdentifierGeneratorFactory.java:104)
... 6 more
%%%% Error Creating SessionFactory %%%%
org.hibernate.InvalidMappingException: Could not parse mapping document from resource cn/itcast/hibernate/domain/Person.hbm.xml

解决方法:

myeclipse10自动生成IdCard.hbm.xml文件内容如下

<hibernate-mapping>
    <class name="cn.itcast.hibernate.domain.IdCard" table="id_card" catalog="test">
        <id name="id" type="java.lang.Integer">
          <column name="id" />
          <generator class="foreign"></generator>
        </id>
        <one-to-one name="person" class="cn.itcast.hibernate.domain.Person" constrained="true"></one-to-one>
        <property name="usefulLife" type="java.util.Date">
            <column name="useful_life" length="10" not-null="true" />
        </property>
    </class>
</hibernate-mapping>

应该改为:

<id name="id" type="java.lang.Integer">
          <generator class="foreign">
          <param name="property">person</param>
        </generator>
        </id>





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值