views:

138

answers:

1

Hi, I am using NetBeans 6.8 for building Spring MVC application.

Technologies :

  • Spring MVC 2.5
  • Derby DB
  • Hibernate for ORM
  • GlassFish v3 server

I use New JPA Controller Classes from Entity Classes for adding ORM file. It is supposed to generate class for managing queries with my POJO files.

Problem is, that NetBeans generates following code, and won't compile :

public int getBrandCount() {
        EntityManager em = getEntityManager();
        try {
            CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
            Root<Brand> rt = cq.from(Brand.class);
            cq.select(em.getCriteriaBuilder().count(rt));
            Query q = em.createQuery(cq);
            return ((Long) q.getSingleResult()).intValue();
        } finally {
            em.close();
        }
    }

At the picture, there is NetBeans error : alt text

It looks like method getCriteriaBuilder of Entity Manager Interface is unimplemented. Or some other reason why I can't use it in code.

I don't know what other info should I provide, so please ask if anything comes to your mind.

Thanks

+1  A: 

NetBeans is generating JPA 2.0 code so you need the JPA 2.0 API on your class path to compile your code (and a JPA 2.0 provider to run it). Since you're using Hibernate, here are the required libraries to use Hibernate Entity Manager 3.5.1-Final:

org.hibernate:hibernate-entitymanager:jar:3.5.1-Final:compile
+- org.hibernate:hibernate-core:jar:3.5.1-Final:compile
|  +- antlr:antlr:jar:2.7.6:compile
|  +- commons-collections:commons-collections:jar:3.2:compile
|  +- dom4j:dom4j:jar:1.6.1:compile
|  |  \- xml-apis:xml-apis:jar:1.0.b2:compile
|  \- javax.transaction:jta:jar:1.1:compile
+- org.hibernate:hibernate-annotations:jar:3.5.1-Final:compile
|  \- org.hibernate:hibernate-commons-annotations:jar:3.2.0.Final:compile
+- cglib:cglib:jar:2.2:compile
|  \- asm:asm:jar:3.1:compile
+- javassist:javassist:jar:3.9.0.GA:compile
\- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.0.Final:compile
Pascal Thivent
It seems that JPA 2.0 + Derby DB aren't great friends. It actually works better with MySQL :-|
Xorty
This has IMO nothing to do with MySQL or Derby (which works fine with JPA 2.0).
Pascal Thivent
You were correct, libs problem. Thx
Xorty