TransWikia.com

Mark non db fields @Transient vs extent JPA Entity?

Stack Overflow Asked by bluelurker on December 7, 2021

We have a JPA Entity. Once the entity is persisted in db, some fields of this entity(db columns) along with some other data (which is not part of this entity) has to be stored in a JCR object-store.

Should I create one single Entity(JPA) for both DB and JCR and just add JCR fields in Entity and mark them @Transient?

or

Should I use inheritance or composition(using JPA Entity) and create a new JCR specific object? Basically, should JPA entities be strictly used for DB or is @Transient in this case an abuse?

One Answer

should JPA entities be strictly used for DB or is @Transient in this case an abuse?

Not an abuse but you will need to tread very carefully with JPA operations. One merge or refresh too many and your transient field value is lost.

Personally I'd create another layer of abstraction over both JPA and JCR that would manage your domain object as POJOs, some sort of DomainObjectRepository that would handle CRUD operations, interacting with both JPA and JCR, and encapsulating the mapping from/to both storage technologies (with mapping layer to each technology having a dedicated set of objects - JPA entities, JCR nodes).

Answered by crizzis on December 7, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP