Reputation: 4327
Is it possible to use hibernate as Glassfish's persistence provider and if so HOW?
Upvotes: 1
Views: 6256
Reputation: 21
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.
Upvotes: 2
Reputation: 32315
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
Upvotes: 2
Reputation: 2180
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>
Upvotes: 4
Reputation: 18149
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.
Upvotes: 2