Win a copy of Serverless Applications with Node.js this week in the NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

cannot use correlate to Join in Hibernate  RSS feed

 
Ranch Hand
Posts: 1729
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I am practicing with ToyAppForJPA.
I did this:


CriteriaBuilder cb= em.getCriteriaBuilder();
CriteriaQuery c= cb.createQuery(CustOrder.class);
Root custOrderRoot = c.from(CustOrder.class);
Join oliJoin = custOrderRoot.join("lineItems");

Subquery  sq = c.subquery(Integer.class);
Join sqJoin =sq.correlate(oliJoin);

sq.select (cb.max(sqJoin.get("quantity")));

c.where(cb.equal(oliJoin.get("quantity"),sq));
c.select(custOrderRoot);
TypedQuery q = em.createQuery(c);
List result = q.getResultList();


lineItems is an attribute of the CustOrder  and is a type of OrderLineItem.
quantity is an integer of OrderLineItem.

I got this from Hibernate , which cannot take a Join as a Root? The from expression is missing a root in the subquery in Hibernate.


Target exception: java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: ) near line 1, column 197 [select generatedAlias0 from salesapp.CustOrder as generatedAlias0 inner join generatedAlias0.lineItems as generatedAlias1 where generatedAlias1.quantity=(select max(generatedAlias1.quantity) from )]
]

 
Himai Minh
Ranch Hand
Posts: 1729
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I tried to fix this issue by updating the pom.xml so that I get the latest Hibernate entitymanager and provider.
In Netbean 8.2,
I did this:


//In pom.xml, the original version is 4.0.0CR7. Now, I updated it to 4.3.11.Final. There is a 5.2.10 version, but Netbean does not download this latest version.
<dependency>
           <groupId>org.hibernate</groupId>
           <artifactId>hibernate-entitymanager</artifactId>
           <version>4.3.11.Final</version>
       </dependency>



//In persistence.xml, it was org.hibernate.ejb.HibernatePersistenceProvider
<persistence-unit name="myPU" transaction-type="RESOURCE_LOCAL">
   <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>



It compiles fine. But when I run it, I got this error, saying that it cannot find the provider;


Jul 05, 2017 7:12:14 PM org.hibernate.ejb.HibernatePersistence logDeprecation
WARN: HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
Jul 05, 2017 7:12:14 PM org.hibernate.ejb.HibernatePersistence logDeprecation
...
Jul 05, 2017 7:12:15 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.3.11.Final}
Jul 05, 2017 7:12:15 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Jul 05, 2017 7:12:15 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Jul 05, 2017 7:12:15 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
Exception in thread "main" java.lang.ExceptionInInitializerError
...
Caused by: javax.persistence.PersistenceException: Unable to build entity manager factory

... 3 more
Caused by: org.hibernate.engine.jndi.JndiException: Error parsing JNDI name []
...
Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
...

 
It is no measure of health to be well adjusted to a profoundly sick society. -Krishnamurti Tiny ad:
global solutions you can do at home or in your backyard
https://www.kickstarter.com/projects/paulwheaton/better-world-boo
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!