2013-03-21 101 views
0

我有一个连接表的一对多映射。Hibernate与连接表的一对多映射属性访问

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

服务和代码类是设置为休眠的实体,他们有他们的IDS存取器。

连接表

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 

回答

0

自己弄明白了。 “代码”类是使用JPA注释设置的,并且在属性声明中设置了注释。在实体属性的getter方法上设置注释解决了这个问题。