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

后端 未结 2 933
走了就别回头了
走了就别回头了 2020-12-04 09:02

Lets say I have the following POJO:

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

2条回答
  •  独厮守ぢ
    2020-12-04 09:52

    It is possible:

    • you can map it with XML - make an orm.xml (conforming to the orm schema), and map the columns of your POJO, without even extending it. It will be JPA-enabled in one environment, and a POJO in the other one
    • override just the getter methods and annotate them - (I'm not sure if this will work)

    That said, I don't think it is necessary to do this. Just annotate your POJO, and add the compile-time dependency to your projects. Then each project will decide whether it will use them as JPA entities or not.

提交回复
热议问题