开发者

many-to-many hibernate with AutoPopulatingList incurred a PropertyAccessException

I've got this problem that It always hit the PropertyAccessException when trying to saveOrUpdate(); I'm using Spring 3 and hibernate 3.6 with tomcat 7.

I've got a M-M Akte to Pemilik

Here is the code: (Simple properties are omitted for the sake of brevity)

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;
    }

开发者_如何学Go    public void setVersion(int version) {
        this.version = version;
    }

    public Set getAktes() {
        return aktes;
    }

    public void setAktes(Set aktes) {
        this.aktes = aktes;
    }

}

here are the mapping files

<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>

now i was trying to save it during processFinish()

by doing something like: akteService.createAkte(cmd.getAkte()); Inside the Akte there is a AutoPopulatingList that contained Pemilik object. and AutoPopulatingList is initiated the simple way new AutoPopulatingList(Pemilik.class);

and here is the stack trace

org.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling setter of com.notaris.beans.Akte.pemiliks 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)

Any ideas guys? I've taken a look at the pemiliks property, it's just a simple AutoPopulatingList, I dont understand what's the issue with the setter not able to access it? Thank you.


The type of a collection that needs to be managed by hibernate should be a java.util.Set or List. The error is most likely due to pemiliks being of type AutoPopulatingList, change it to a List (also the setter & getter). You can initialize the collection to an instance of AutoPopulatingList.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜