我遇到了这个问题,它在尝试saveOrUpdate()时总是遇到PropertyAccessException;我正在使用Spring 3和hibernate 3.6与tomcat 7。
我有一个M-M Akte到Pemilik
以下是代码:(为简洁起见,省略了简单属性)
public class Akte implements Serializable, Comparable {
private Long id;
private int version;
AutoPopulatingList pemiliks;
public Akte() {
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public int getVersion() {
return version;
}
public void setVersion(int version) {
this.version = version;
}
public AutoPopulatingList getPemiliks() {
return pemiliks;
}
public void setPemiliks(AutoPopulatingList pemiliks) {
this.pemiliks = pemiliks;
}
}
public class Pemilik implements Serializable {
private Long id;
private int version;
private Set aktes = new HashSet();
public Pemilik() {}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public int getVersion() {
return version;
}
public void setVersion(int version) {
this.version = version;
}
public Set getAktes() {
return aktes;
}
public void setAktes(Set aktes) {
this.aktes = aktes;
}
}
这是映射文件
<hibernate-mapping package="com.notaris.beans">
<class name="Akte" table="AKTE" dynamic-insert="true" dynamic-update="true" lazy="true">
<id name="id" column="AKTE_ID">
<generator class="native"/>
</id>
<version name="version" column="VERSION"/>
<bag name="pemiliks" table="AKTE_PEMILIK" lazy="true" cascade="save-update">
<key column="AKTE_ID"/>
<many-to-many class="Pemilik" column="PEMILIK_ID"/>
</bag>
</class>
</hibernate-mapping>
<hibernate-mapping package="com.notaris.beans">
<class name="Pemilik" table="PEMILIK" lazy="true">
<id name="id" column="PEMILIK_ID">
<generator class="native"/>
</id>
<version name="version" column="VERSION"/>
<set name="aktes" table="AKTE_PEMILIK" lazy="true" inverse="true" cascade="save-update">
<key column="PEMILIK_ID"/>
<many-to-many class="Akte" column="AKTE_ID"/>
</set>
</class>
</hibernate-mapping>
现在我试图在processFinish()
期间保存它做类似的事情: akteService.createAkte(cmd.getAkte()); 在Akte内部有一个包含Pemilik对象的AutoPopulatingList。 和AutoPopulatingList以简单的方式启动新的AutoPopulatingList(Pemilik.class);
这是堆栈跟踪
org.hibernate.PropertyAccessException:调用com.notaris.beans.Akte.pemiliks的setter时发生IllegalArgumentException org.hibernate.property.BasicPropertyAccessor $ BasicSetter.set(BasicPropertyAccessor.java:128) org.hibernate.tuple.entity.AbstractEntityTuplizer.setPropertyValues(AbstractEntityTuplizer.java:583) org.hibernate.tuple.entity.PojoEntityTuplizer.setPropertyValues(PojoEntityTuplizer.java:229) org.hibernate.persister.entity.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:3822) org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:299) org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:203) org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:129) org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210) org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195) org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:117) org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93) org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:685) org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:677) org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:673) org.springframework.orm.hibernate3.HibernateTemplate $ 16.doInHibernate(HibernateTemplate.java:740) org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406) org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374) org.springframework.orm.hibernate3.HibernateTemplate.saveOrUpdate(HibernateTemplate.java:737) com.notaris.dao.AkteDaoImpl.createAkte(AkteDaoImpl.java:26) com.notaris.service.AkteService.createAkte(AkteService.java:22) com.notaris.controller.AddAkteController.processFinish(AddAkteController.java:228) org.springframework.web.servlet.mvc.AbstractWizardFormController.validatePagesAndFinish(AbstractWizardFormController.java:650) org.springframework.web.servlet.mvc.AbstractWizardFormController.processFormSubmission(AbstractWizardFormController.java:500) org.springframework.web.servlet.mvc.AbstractFormController.handleRequestInternal(AbstractFormController.java:268) org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153) org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644) org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560) javax.servlet.http.HttpServlet.service(HttpServlet.java:641) javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
任何想法的家伙? 我看了一下pemiliks属性,它只是一个简单的AutoPopulatingList,我不知道 了解setter无法访问它的问题是什么? 谢谢。
答案 0 :(得分:1)
需要由hibernate管理的集合类型应该是java.util.Set或List。该错误很可能是由于pemiliks属于AutoPopulatingList类型,将其更改为List(也就是setter&amp; getter)。您可以将集合初始化为AutoPopulatingList的实例。