【问题标题】:Hibernate One to many mapping with join table propertyaccessexceptionHibernate 使用连接表属性访问异常的一对多映射
【发布时间】:2013-03-27 11:27:24
【问题描述】:

我有一个连接表的一对多映射。

class service{private Long service_id}
class codes{private Long code_id}

服务和代码类被设置为休眠实体,并且它们的 id 具有修改器。

连接表

table servicecodes
(serviceid,
codeid);

我的服务类映射:

<class name="path.to.Service" table="SERVICE"
lazy="false">

 <set name="sc" table="ServiceCodes">
    <key column="serviceid"/>
    <many-to-many column="codeid" unique="true"
        class="path.to.Codes"/>
 </set>
</class>

在我的应用层我有:

serviceobj.set(Set<Codes>);
...
session.save(serviceobj);

在 session.save 行,抛出以下错误:

org.hibernate.PropertyAccessException: could not get a field value by reflection    getter of path.to.Codes.code_id
....
Caused by: java.lang.IllegalArgumentException: Can not set java.lang.Long field path.to.Codes.code_id to java.lang.String

【问题讨论】:

    标签: hibernate join one-to-many


    【解决方案1】:

    这是我自己想出来的。 'codes' 类是使用 JPA 注释设置的,并且注释是在属性声明上设置的。在实体属性的getter方法上设置注释解决了这个问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-11-15
      • 1970-01-01
      • 1970-01-01
      • 2012-07-12
      • 1970-01-01
      • 2012-05-04
      • 2014-07-07
      • 1970-01-01
      相关资源
      最近更新 更多