org.hibernate.PropertyAccessException:调用getter时发生IllegalArgumentException

时间:2012-06-21 07:31:00

标签: java hibernate

我尝试将我的应用程序从Hibernate 3.2升级到Hibernate 3.5.6,然后我得到以下我以前没有的异常:

org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of Employee.phoneNumbers    
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:198) ~[hibernate-core-3.5.6-Final.jar:3.5.6-Final]
at org.hibernate.tuple.entity.AbstractEntityTuplizer.getPropertyValue(AbstractEntityTuplizer.java:506) ~[hibernate-core-3.5.6-Final.jar:3.5.6-Final]
at org.hibernate.tuple.entity.AbstractEntityTuplizer.getPropertyValue(AbstractEntityTuplizer.java:524) ~[hibernate-core-3.5.6-Final.jar:3.5.6-Final]
at org.hibernate.persister.entity.AbstractEntityPersister.getPropertyValue(AbstractEntityPersister.java:3844) ~[hibernate-core-3.5.6-Final.jar:3.5.6-Final]
at org.hibernate.engine.StatefulPersistenceContext.isFoundInParent(StatefulPersistenceContext.java:1236) ~[hibernate-core-3.5.6-Final.jar:3.5.6-Final]
at org.hibernate.engine.StatefulPersistenceContext.getOwnerId(StatefulPersistenceContext.java:1146) ~[hibernate-core-3.5.6-Final.jar:3.5.6-Final]
at org.hibernate.property.BackrefPropertyAccessor$BackrefGetter.getForInsert(BackrefPropertyAccessor.java:139) ~[hibernate-core-3.5.6-Final.jar:3.5.6-Final]
at org.hibernate.tuple.entity.AbstractEntityTuplizer.getPropertyValuesToInsert(AbstractEntityTuplizer.java:500) ~[hibernate-core-3.5.6-Final.jar:3.5.6-Final]
at org.hibernate.tuple.entity.PojoEntityTuplizer.getPropertyValuesToInsert(PojoEntityTuplizer.java:255) ~[hibernate-core-3.5.6-Final.jar:3.5.6-Final]
at org.hibernate.persister.entity.AbstractEntityPersister.getPropertyValuesToInsert(AbstractEntityPersister.java:3952) ~[hibernate-core-3.5.6-Final.jar:3.5.6-Final]
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:290) ~[hibernate-core-3.5.6-Final.jar:3.5.6-Final]
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:204) ~[hibernate-core-3.5.6-Final.jar:3.5.6-Final]
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:144) ~[hibernate-core-3.5.6-Final.jar:3.5.6-Final]
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210) ~[hibernate-core-3.5.6-Final.jar:3.5.6-Final]
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195) ~[hibernate-core-3.5.6-Final.jar:3.5.6-Final]
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:117) ~[hibernate-core-3.5.6-Final.jar:3.5.6-Final]
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93) ~[hibernate-core-3.5.6-Final.jar:3.5.6-Final]
at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:677) ~[hibernate-core-3.5.6-Final.jar:3.5.6-Final]
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:669) ~[hibernate-core-3.5.6-Final.jar:3.5.6-Final]
at org.hibernate.engine.CascadingAction$5.cascade(CascadingAction.java:252) ~[hibernate-core-3.5.6-Final.jar:3.5.6-Final]
at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:392) ~[hibernate-core-3.5.6-Final.jar:3.5.6-Final]
at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:335) ~[hibernate-core-3.5.6-Final.jar:3.5.6-Final]
at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:204) ~[hibernate-core-3.5.6-Final.jar:3.5.6-Final]
at org.hibernate.engine.Cascade.cascade(Cascade.java:161) ~[hibernate-core-3.5.6-Final.jar:3.5.6-Final]
at org.hibernate.event.def.AbstractSaveEventListener.cascadeBeforeSave(AbstractSaveEventListener.java:451) ~[hibernate-core-3.5.6-Final.jar:3.5.6-Final]
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:283) ~[hibernate-core-3.5.6-Final.jar:3.5.6-Final]
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:204) ~[hibernate-core-3.5.6-Final.jar:3.5.6-Final]
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:144) ~[hibernate-core-3.5.6-Final.jar:3.5.6-Final]
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210) ~[hibernate-core-3.5.6-Final.jar:3.5.6-Final]
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:56) ~[hibernate-core-3.5.6-Final.jar:3.5.6-Final]
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195) ~[hibernate-core-3.5.6-Final.jar:3.5.6-Final]
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:50) ~[hibernate-core-3.5.6-Final.jar:3.5.6-Final]
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93) ~[hibernate-core-3.5.6-Final.jar:3.5.6-Final]
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:705) ~[hibernate-core-3.5.6-Final.jar:3.5.6-Final]
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:693) ~[hibernate-core-3.5.6-Final.jar:3.5.6-Final]
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:689) ~[hibernate-core-3.5.6-Final.jar:3.5.6-Final]

...

Caused by: java.lang.IllegalArgumentException: java.lang.ClassCastException@424ada59
    at sun.reflect.GeneratedMethodAccessor376.invoke(Unknown Source) ~[na:na]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[na:1.6.0_26]
    at java.lang.reflect.Method.invoke(Method.java:597) ~[na:1.6.0_26]
    at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:172) ~[hibernate-core-3.5.6-Final.jar:3.5.6-Final]

我在此页stack overflow上发现它可能是缓存的问题。我还在使用ehcache,没有改变它。所以我试图禁用它,我仍然有问题。

此问题发生在此方法

@Transactional
public void createLocalEntriesForEmployeeType(List<RemotePhone> dataToBeAddedLocally, Integer employeeId) {
{
    for (RemotePhone remote : dataToBeAddedLocally) {
        ExternalDetails externalDetails = new ExternalDetails();
        externalDetails.setRemoteId(remote.getRemoteId().toString());
        externalDetails.setLastUpdated(remote.getUpdateDate());
        EmployeePhoneNumber localPhone = createLocalPhone(remote);

        employeeService.savePhoneNumber(localPhone, employeeId);

        ExternalPhoneDetails externalPhoneDetails = new externalPhoneDetails();
        externalPhoneDetails.setPayrollDataType(localPhone);
        externalPhoneDetails.setExternalDetails(externalDetails);
        externalDao.save(externalPhoneDetails);
    }
}

savePhoneNumber方法是:

@Transactional
public void savePhoneNumber(EmployeePhoneNumber phoneNumber, Integer employeeId) {
    validationService.assertValid(phoneNumber, "employeePhoneNumber");
    Employee employee = getEmployee(employeeId);
    employee.getPhoneNumbers().add(phoneNumber);
}

映射是:

<class
    name="Employee"
    table="EMPLOYEE"
    lazy="true"
>
    <id
        name="id"
        column="EMPLOYEEID"
        type="java.lang.Integer"
        unsaved-value="undefined"
    >
        <generator class="sequence">
            <param name="sequence">EMPLOYEEID_SEQ</param>
        </generator>
    </id>

    <property name="firstName" column="FIRSTNAME" type="java.lang.String"/>
    <bag
        name="phoneNumbers"
        table="PHONE_NUMBERS"
        cascade="all, delete-orphan"
        lazy="true"
        order-by="id"
    >
        <key column="EMPLOYEE" not-null="true"/>
        <one-to-many class="EmployeePhoneNumber"/>
    </bag>
</class>

<class name="EmployeePhoneNumber"
       table="PHONE_NUMBERS"
       lazy="true" >

    <id name="id"
        column="ID"
        type="java.lang.Integer"
        unsaved-value="undefined">
          <generator class="sequence">
            <param name="sequence">employee_phone_numbers_id_seq</param>
          </generator>
    </id>

    <property name="number" column="NUMBER" type="java.lang.String"/>
    <many-to-one
        name="employee" 
        class="Employee" 
        column="EMPLOYEE"
        insert="false"
        update="false"
    />
</class>

<class
    name="ExternalDetails"
    lazy="true"
    table="EXTERNAL_DETAILS"
>
    <id
        name="id"
        column="ID"
        type="java.lang.Integer"
        unsaved-value="undefined"
    >
          <generator class="sequence">
              <param name="sequence">EXTERNAL_DETAILS_ID_SEQ</param>
          </generator>
    </id>

    <property name="remoteId"       column="REMOTE_ID"      type="java.lang.String"/>
</class>

<class
    name="ExternalPhoneDetails"
    table="EXTERNAL_PHONE_NUMBER_DETAILS"
    lazy="true"
>
    <id
        name="id"
        column="ID"
        type="java.lang.Integer"
        unsaved-value="undefined"
    >
        <generator class="sequence">
            <param name="sequence">EXTERNAL_PHONE_NUMBER_DETAILS_ID_SEQ</param>
        </generator>
    </id>

    <many-to-one
        name="externalDetails"
        column="EXTERNAL_DETAILS"
        class="ExternalDetails"
        cascade="save-update, delete"
    />

    <many-to-one
        name="payrollDataType"
        column="PHONE_NUMBER"
        class="EmployeePhoneNumber"
        cascade="save-update, delete"
    />
</class>

我找到了一种通过在调用employeeService.savePhoneNumber()之后刷新hibernateSession来解决这个问题的方法,但是我不喜欢这个解决方案,它曾经和Hibernate 3.2一起使用。 这是hibernate 3.5中的一个错误,还是我想要升级时需要更改的内容?

谢谢

0 个答案:

没有答案