Is it possible to use hibernate as Glassfish's persistence provider?

馋奶兔 提交于 2019-12-01 11:37:09

问题


Is it possible to use hibernate as Glassfish's persistence provider and if so HOW?


回答1:


While I'm not an expert on either Glassfish or Hibernate, I think you'd probably find this interesting: Instructions on using Hibernate in Glassfish




回答2:


The link provided by Guss to hibernate.org has expired. Here's a google cache dated Feb 20, 2010. As noted in a previous version of the linked wiki page, it is preferable to keep the hibernate libraries within your .ear / .war rather than the Glassfish install dir so that different applications can use their own version of Hibernate.

Modern How-To

To use hibernate with glassfish, all you have to do is put hibernate and its dependencies into your EAR file. This might also with with a WAR file.

In your persistence.xml, specify hibernate using this tag:

<provider>org.hibernate.ejb.HibernatePersistence</provider>

You can also specify hibernate properties as usual, for example:

<properties>
  <property name="hibernate.hbm2ddl.auto" value="none"/>
</properties>



回答3:


Yes, that's a common scenario. Just deploy Hibernate (and all its dependencies) either globally into Glassfish or as part of your application. Then implement your application using Hibernate as a library.

The next question you have to consider is whether you want to use JPA, and Hibernate as JPA provider or if you want to use Hibernate plain.

Another question then if you want to use EJBs and Entity Beans. If yes, I would recomend using JPA.

If you are not using EJB Entity Beans, you can use either JPA or plain Hibernate for persisting your POJOs.




回答4:


Instead of putting the Hibernate libs in the Glassfish server lib directory you can build an EAR and include them within the EAR's lib directory. I just posted a blog entry on our experiences with this approach. IMO it's better to bundle Hibernate with the application itself instead of changing the server's global configuration. By doing so it wont affect other applications that may also be running on the same server (e.g., legacy applications). See this for more info.



来源:https://stackoverflow.com/questions/594079/is-it-possible-to-use-hibernate-as-glassfishs-persistence-provider

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!