问题标签 [entitymanager]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
28398 浏览

java - When should EntityManagerFactory instance be created/opened?

Ok, I read bunch of articles/examples how to write Entity Manager Factory in singleton.

One of them easiest for me to understand a bit:

http://javanotepad.blogspot.com/2007/05/jpa-entitymanagerfactory-in-web.html

I learned that EntityManagerFactory (EMF) should only be created once preferably in application scope.

And also make sure to close the EMF once it's used (?)

So I wrote EMF helper class for business methods to use:

And my method using EmProvider:

I made sure to close EntityManager (em) within method level as suggested. But when should EntityManagerFactory be closed then? And why EMF has to be singleton so bad??? I read about concurrency issues but as I am not experienced multi-thread-grammer, I can't really be clear on this idea.

0 投票
1 回答
1275 浏览

spring - EntityManager 和两个带有 PersistenceContextType.EXTENDED 的 DAO

我的应用程序中的实体管理器有问题。我有两个这样的 DAO 类:

第二个 DAO 用于 ClassB,看起来类似于 DaoA。其余的事情由 Spring 框架为我完成。

当我调试应用程序时,我发现两个 DAO 对象都有不同的 EntityManager 实例。结果,我的两个不同的 DAO 与不同的 PersistenceContext 连接。

问题是这是否是正确的行为?我想为我的所有 DAO 类使用相同的 PersistenceContext。如果可能并且我是否正确理解了 JPA,请给我一个提示?

问候 HSD

0 投票
1 回答
1050 浏览

java - TestNG:确定下一个测试方法

我的目标是在每个测试方法之后清除()我的 javax.persistence.EntityManager。

下面是一个测试类的例子:

entityManager 在 dataProvider "sampleDataProvider" 中使用,通过查询 DB 中的测试数据,然后以这种格式编译:new Object[2][1]. 请记住,数据的查询和编译都是在测试方法(使用@DataProvider 注释)实际运行之前完成的,我们实际上是在查询实体而不仅仅是字符串。

上面的测试类会像这样运行:

我最初的解决方案是使用@AfterTest注释来清除 entityManager。但是,它会"some queried entity 2"在第二次运行(或第二次测试实例)之前与 entityManagertestA分离,testB这会导致对"some queried entity 2".

我的目标是在测试方法之后清除 entityManager ,而不必在测试方法的每个实例之后清除。

TestNG 是否可以知道接下来运行哪个测试?这样,如果下一个测试是新测试,我可以轻松清除 entityManager。

还有其他建议吗?

0 投票
1 回答
695 浏览

hibernate - javax.persistence.entitymanager 是 JPA 接口吗?

今天我很困惑。javax.persistence.entitymanager 是 JPA 接口吗?

谢谢

0 投票
1 回答
967 浏览

testng - TestNG Listeners: Intercepting @DataProvider

This is a follow up question to this:

TestNG: Identifying which tests methods are next

I realize now that it's possible to intercept test methods. However, it seems that the best time to safely clear the entityManager is before a @DataProvider method is executed.

Is this possible?

0 投票
4 回答
22342 浏览

java - Java /JPA | 具有指定继承类型的查询

我正在对通用表“Sample”构建查询,并且我有几种从该表“SampleOne”、“SampleTwo”继承的类型。我需要这样的查询:

其中 type 将是表的鉴别器值。是否有可能以任何方式(并避免创建特定于实体的查询,每个 SampleOne、SampleTwo ... 等一个)

我将非常感谢对此主题的任何意见,

亲切的问候,P。

0 投票
2 回答
12389 浏览

model-view-controller - 模型中的 Symfony2 entityManager

我将在我的模型中使用 entity_manager。但 entity_manager 仅在 controller: 中可用throw $em = $this->get('doctrine.orm.entity_manager')。所以,我必须用$em参数定义模型方法。这使得 phpUnit 测试变得非常困难并且违反了应用程序结构。例如:

有什么方法可以在模型部分使用 entity_manager 服务吗?

0 投票
1 回答
3440 浏览

hibernate - Seam - 通过 (Session)em.getDelegate() 获取连接;

我使用Seam 框架。

如果我做

那么这是一个新的连接吗?我必须手动关闭连接吗?

我在 Weblogic 应用服务器的循环中对此进行了测试:

而且我从未在控制台中看到 Weblogic 池限制资源不足,也没有强制非活动连接到池。

0 投票
1 回答
1011 浏览

java - 无状态resteasy EntityManager注入?

JBoss 6.

我被引导相信我可以将一个类标记为@Stateless 并将其注释为一个 resteasy 网络服务。

到目前为止一切都很好,我的代码似乎可以部署和运行。

但是,一如既往......我的 EntityManager 没有被注入并且保持为空。我尝试创建另一个没有resteasy注释的类,将其标记为@Stateless,注入EntityManager并将其注入我的resteasy Web服务,但这次注入另一个无状态会话bean为空。

我应该能够将 EntityManager 注入@Stateless resteasy Web 服务吗?如果没有,我怎样才能得到一个 - 我没有任何运气来创建无状态会话 bean 并将其注入到 servlet 中?

提前致谢。

0 投票
3 回答
3419 浏览

gwt - GWT RequestFactory:如何为每个请求使用单个 EntityManager

为了持久RequestFactory附加的实体,我需要确保EntityManager对每个请求都使用相同的。

我基于实现拼凑了我自己的工厂类ThreadLocal,但我不确定如何正确释放资源(例如如何知道请求已经完成并调用close())。

有没有一种简单的方法来确保在整个给定的 ServletRequest 中使用单个 EntityManager 而无需求助于完整的 J2EE/CDI?如果必须的话,我会走这条路,但我希望保持简单,特别是因为我想继续使用 GWT 附带的轻量级开发服务器。