views:

985

answers:

3

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

+2  A: 

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

Guss
Cheers Guss. I just came across that myself too. I've started posting questions before I even Google them. It's a good way to keep track of your thoughts though. I'll let you know how I get on.
montyontherun
@Guss it is a shame that link doesn't work anymore. I cant seem to find that one. All the ones I find just say to put them in the glassfish lib folder.
jschoen
+2  A: 

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.

jbandi
+1  A: 

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>
John K