You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by Janko Heilgeist <ja...@rzg.mpg.de> on 2007/09/21 15:57:45 UTC

Bug/problem deserializing an enhanced class

Hi,

I previously posted about my problem on the geronimo-user mailing list,
so some of you may have seen parts of this mail before. Thanks to the
help of David Jencks and Jarek Gabor I was able to isolate the core of
my problem and write a unit-test for OpenJPA (see attachment).

In my code I derive an entity from an interface, that uses generics:

public interface GenericEntity<PK extends Serializable> {
	PK getEntityId();
	void setEntityId();
}

public interface LongObjIdEntity extends GenericEntity<Long> {
}

@Entity
public class SomeEntity implements LongObjIdEntity, Serializable {
	private Long entityId;

	@Id
	@GeneratedValue
	Long getEntityId() {
		return entityId;
	}
	void setEntityId(Long entityId) {
		this.entityId = entityId;
	}
}

The enhancement process of OpenJPA seems to scramble the class somehow,
so that serialized objects can no longer be deserialized. More exactly
the call

	Class.getDeclaredField("entityId");

somewhere inside the computation of the serialVersionUID inside the
ObjectOutputStream.readObject() method fails with a VerifyError. This
only happens if the @Id @GeneratedValue annotations are applied to the
getter/setter for PROPERTY-access (or instead of annotations the orm.xml
contains the access-type="PROPERTY" attribute). FIELD-access produces no
problems at all.

The attached unit-test contains tests for both cases and PROPERTY-access
fails reliably with release 1.0.0 and the current SVN-version of
OpenJPA. The stacktrace is:

java.lang.VerifyError: (class:
org/apache/openjpa/persistence/generics/SomeEntityWithPropertyAccess,
method: getEntityId signature: ()Ljava/lang/Long;) Wrong return type in
function
	at java.lang.Class.getDeclaredFields0(Native Method)
	at java.lang.Class.privateGetDeclaredFields(Class.java:2259)
	at java.lang.Class.getDeclaredField(Class.java:1852)
	at
org.apache.openjpa.persistence.generics.TestEnhancementOfGenerics.testPropertyAccess(TestEnhancementOfGenerics.java:21)


Regards, Janko