如何通过动态 EJB-QL 从独立缓存加载 JPA 实体,而不访问数据库
我有一个通过动态 ejb ql 查询加载的 JPA 实体,用户可以相当自由地配置该查询。出现了一个新要求:仅当用户特定查询返回这些新实体时,才应允许用户创建新实体。因此,我认为我需要实例化一个 JPA 实体,动态创建一个 EJB 查询,并确定如果该实体存在于数据库中,该实体是否会被该查询加载。
我怎么能这么做呢?例如,是否有一个独立的 JPA 缓存,以便我可以将新的 JPA 实体推送到缓存中并通过查询对其进行查询,而无需访问数据库?
I've got a JPA entity that is loaded via dynamic ejb ql queries that can be configured by the user fairly freely. In comes a new requirement: Users should be allowed to create new entities only iff these new entites would be returned by their user specific queries. So, I think I'd need to instanciate a JPA-Entity, create an EJB-Query dynamically and figure out if the entity would be loaded by this query if it existed in the database.
How could I do that? Is there, for example, a standalone JPA cache so that I could push the new JPA entity into the cache and question it with my query, without ever hitting the database?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将新实体插入数据库,执行查询,查看是否找到实体,如果找不到则回滚(如果不想回滚,则在同一事务中删除实体)。
You could just insert the new entity in database, perform the query, see if the entity is found, and rollback if not found (or delete the entity in the same transaction if you don't want to rollback).