0

アプリケーションを 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]

このページスタック オーバーフローで、キャッシュに問題がある可能性があることがわかりました。私はまだ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 のバグですか、それともアップグレードしたい場合に変更する必要があるものですか?

ありがとうございました

4

0 に答える 0