2013-03-21 67 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方法上設置註釋解決了這個問題。