JPA / Hibernate: can I have a parent without annotations and a child with

I have a requirement to create a component that can be used stand-alone or in a larger application. When using offline mode, it should not require a database, as well as dependencies associated with the database / ORM. When used as part of a larger application, some of the classes will actually be stored in the database through JPA / Hibernate.

I thought that the domain objects in the component would not contain annotations (due to the requirement not to have dependencies associated with ORM). In a larger application, I would then subclass these domain objects ... as for how much I did it.

As a rule, I use field level annotations. Is this possible due to the scenario described above? I dont think about it.

Another thought that I had to switch to annotating properties. In this case, I would expand the non-annotated domain object by overriding all the properties and annotating them. The child will be just a delegate with the required annotations. It just looks like work / code.

Ironically, I think it would be easier to do if I used hbm.xml, which we recently left. Am I missing something with annotations?

+3
source share
2 answers

JPA annotations are truly your only addiction. If someone uses your object in POJO (not a database), then all they need is a JPA annotation banner, which for most application servers is actually on the way to classes.

, , , , .

, hbm . , hibernate hbm SessionFactory, , .

+3

, , .

, . , , . , . , ( ) ..

xml . () , xml . , , .

xml, HibernateTools, ( , ).

, . , . , .

. . ( ), , , ... , ( )...

0

Source: https://habr.com/ru/post/1715119/


All Articles