将非数据库字段标记为@Transient与扩展JPA实体? [英] Mark non db fields @Transient vs extent JPA Entity?

查看:267
本文介绍了将非数据库字段标记为@Transient与扩展JPA实体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个JPA Entity.将实体保留在db中之后,该实体的某些字段(db列)以及其他一些数据(不属于该实体)必须存储在JCR对象存储中.

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.

我应该为DB和JCR创建一个单一的Entity(JPA),然后在Entity中添加JCR字段并将其标记为@Transient?

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

是否应该使用继承或组合(使用JPA实体)并创建一个新的JCR特定对象?基本上,应将JPA实体严格用于数据库,还是@Transient在这种情况下是滥用?

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?

推荐答案

JPA实体应严格用于数据库,还是@Transient在这种情况下是滥用?

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

这不是滥用,但是您需要非常小心地执行JPA操作. mergerefresh太多,则会丢失您的瞬态字段值.

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.

我个人将在JPA和JCR上创建另一层抽象,将您的域对象作为POJO管理,某种DomainObjectRepository可以处理CRUD操作,与 both 和JPA以及JCR,并封装两种存储技术之间的映射(到每个具有专用对象集的技术的映射层-JPA实体,JCR节点).

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

这篇关于将非数据库字段标记为@Transient与扩展JPA实体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆