How to handle JPA annotations for a pointer to a generic interface

Posted by HDave on Stack Overflow See other posts from Stack Overflow or by HDave
Published on 2010-05-11T05:19:16Z Indexed on 2010/05/11 5:24 UTC
Read the original article Hit count: 286

Filed under:
|
|
|

I have a generic class that is also a mapped super class that has a private field that holds a pointer to another object of the same type:

@MappedSuperclass
public abstract class MyClass<T extends MyIfc<T>>
    implements MyIfc<T>
    {

        @OneToOne()
        @JoinColumn(name = "previous", nullable = true)
        private T previous;

             ...
             }

My problem is that Eclipse is showing an error in the file at the OneToOne "Target Entity "T" for previous is not an Entity." All of the implementations of MyIfc are, in fact, Entities. I should also add that each concrete implementation that inherit from MyClass uses a different value for T (because T is itself) so I can't use the "targetEntity" attribute.

I guess if there is no answer then I'll have to move this JPA annotation to all the concrete subclasses of MyClass. It just seems like JPA/Hibernate should be smart enough to know it'll all work out at run-time. Makes me wonder if I should just ignore this error somehow.

© Stack Overflow or respective owner

Related posts about jpa

Related posts about annotation