在JPA / Hibernate启动之前引导EJB3应用程序 [英] Bootstrap EJB3 application before JPA / Hibernate startup
问题描述
我有一个EJB3项目(JAR的EAR包装,没有WAR),我试图将Flyway(数据库迁移)集成到其中。
一些选项可以创建一个钩子,让我可以在Hibernate开始做它的事情之前运行代码(绑定到实体等);
- 使用
@StartUp
注释。这不幸的是在JPA启动后运行。 -
ServletContextListener
/@WebListener
。但是,当然你需要一个WEB-INF /
目录才能工作。 - 看看使用
@DependsOn
注释来查看我是否可以在Hibernate之前运行一个类,但无法获得 - 我现在在Hibernate 3.6上,碰到Hibernate 4(从而得到
Integrator
API)是并非真正的选择。
我还有其他选择吗? >解决方案
我确实认为如果您不想让JPA启动,您将需要使用非jta-datasource的RESOURCE_LOCAL事务。
<如果您使用任何类型的JTA事务,JPA将被急切地调用。
像这样JPA只会在启动事务时被调用,但您需要手动控制它。
I have an EJB3 project (EAR packaging of JARs, no WARs) that I'm trying to integrate Flyway (database migrations) into.
I've tried a couple of options to create a hook where I can run code before Hibernate starts doing its thing (binding to entities etc);
- Using the
@StartUp
annotation. This unfortunately gets run AFTER the JPA startup. ServletContextListener
/@WebListener
. But of course you need aWEB-INF/
directory for that to work.- Looked at using the
@DependsOn
annotation to see if I could get a class to run before Hibernate, but couldn't get that to work. - I'm on Hibernate 3.6 at the moment, bumping to Hibernate 4 (and thus getting the
Integrator
API) is not really an option.
Do I have any other options?
I do think that If you do not want to JPA to start you will need to use RESOURCE_LOCAL transaction with non-jta-datasource.
If you use any kind of JTA transactions the JPA will be eagerly invoked.
Like this the JPA will only be invoked when you start a transaction, but you will need to control it manually.
这篇关于在JPA / Hibernate启动之前引导EJB3应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!