views:

1283

answers:

3

Hi,

I created a small desktop project using Hibernate, to understand how enterprise patterns are applied in there.

I'm using annotations, and wrote a class to wrap my session factory

public class Hibernation {

    private static final SessionFactory sessionFactory;

    static{
     try{
      //sesionFactory = new org.hibernate.cfg.Configuration().configure().buildSessionFactory();
      sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
     }
     catch(Throwable e){
      throw new ExceptionInInitializerError(e);
     }
    }

    public static Session getSession(){
     return sessionFactory.openSession();
    }

}

However, whenever i try to run it, I get this error:

Caused by: java.lang.ClassNotFoundException: javax.persistence.ElementCollection

The jars in my classpath do not seem to have that class inside them

hibernate3.jar
jpa.jar
log4j-1.2.15.jar
persistence-api-1.0.jar
slf4j-log4j12-1.0.1.jar

I've looked around for that class, but I can't find where to download it from. Any idea what jar file i'm missing? I looked inside javaee.jar, where there are many javax.persistence.*** clases, but its not there either.

Thanks in advance.

A: 

I had the same problem this morning, and eventually found the solution in this question.

You can download the EclipseLink JPA 2.0 preview implementation from here.

I downloaded the 1.2.0 OSGi bundles zip, and then extracted the javax.persistence_2.0_preview.jar file, which seems to do the trick with Hibernate 3.5.0 beta 2.

Mike Houston
the question is about Hibernate
Bozho
@Bozho - yes, and the answer is about how to get it to work with the new persistence API Draft, hence the mention of 3.5 beta 2 at the end of the answer...
Mike Houston
+1  A: 

Hi,

don't take javax.persistence_2.0_preview.jar from 1.2.0 OSGi bundles zip if you test Hibernate 3.5.0 beta 2, because it is not complete! For example class javax.persistence.criteria.CriteriaBuilder is missing there.

Take following jar indeed: http://repository.jboss.org/maven2/org/hibernate/java-persistence/jpa-api/2.0-cr-1/jpa-api-2.0-cr-1.jar

Generally it is recommended to take all hiberante 3hrd-party jars out from this repository (repository.jboss.org/maven2/org/hibernate/)

regards G.D.

Guenther Demetz
+1 Thanks, had no idea that was there...
Mike Houston
A: 

Try having ejb3-persistence-3.3.2.Beta1.jar (or another version if you wish) on your classpath, and remove the other JPA jars.

Bozho