Is it possible to build a JPA entity by extending a POJO?

Posted by Freiheit on Stack Overflow See other posts from Stack Overflow or by Freiheit
Published on 2010-03-25T14:31:18Z Indexed on 2010/03/25 14:33 UTC
Read the original article Hit count: 351

Filed under:
|

Lets say I have the following POJO:

public class MyThing {
 private int myNumber;
 private String myData;
//assume getter/setter methods
}

Is it now possible to extend this POJO as a JPA entity?

@Entity
@Table(name = "my_thing")
public class MyThingEntity extends MyThing implements Serializable {
 @Column(name = "my_number")
 //?????????
 @Column(name = "my_data")
 //????????
}

I want to keep the POJO separate from the JPA entity. The POJO lives in a different project and is often used without a persistence layer, my project wants to persist it in a database and do so without the overhead of mapping from a POJO to an entity and back.

I understand that JPA entities are POJOs, but in order to use it I would have to include a library that implements javax.persistence and the other projects using the same base object have no use for a persistence layer.

Is this possible? Is this a good idea?

© Stack Overflow or respective owner

Related posts about java

Related posts about jpa