开发者

Hibernate 3.0 + ElementCollection class missing

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 eithe开发者_StackOverflow中文版r.

Thanks in advance.


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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜