简体   繁体   中英

Mark non db fields @Transient vs extent JPA Entity?

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?

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM