Skip to main content

JSR 220 persistence on gereric types fails (b40)

3 replies [Last post]
hewagn00
Offline
Joined: 2006-03-27

I try to persist a generic class, but MetaDataHelper.getReturnTypeFromGeneric() crashes. My entity looks like this:

public class Foo extends FooBar {
private List myVar = new ArrayList();

...
}

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
ss141213
Offline
Joined: 2005-03-30

I don't think that's allowed.

-- Sahoo

hewagn00
Offline
Joined: 2006-03-27

Thanks for your quick reply. Is there a workaround to persist the List? As the code i wrote is completely legal for Java 5, i would think that persisting gereric classes should be possible.

ss141213
Offline
Joined: 2005-03-30

The issue is with the class Foo that defines field of type List. Since T can not be resolved at compile time while parsing Foo.class, it is not allowed to have @Entity or @MappedSuperclass. No work around, that I know of. You have to use real types, e.g.

@Entity class Foo_Employee extends FooBar {
List myVar...
}

@Entity class Foo_Manager extends FooBar {
List myVar...
}

or something similar.

Thanks,
Sahoo