-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: "select a from null as a" with CriteriaQuery
PostPosted: Fri Mar 18, 2011 12:02 pm 
Newbie

Joined: Fri Oct 28, 2005 4:30 am
Posts: 16
Hi,

I'm working on a JPA/Hibernate/Spring application connected to a MySQL database and I test my code using Unitils
hibernate-core and entitymanager 3.6.2.Final
hibernate-jpa-2.0-api 1.0.0.Final
spring 3.0.5.RELEASE
unitils 3.1
MySQL 5.1

Mapping
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="com.mypackage" >

   <class name="Qualifier" table="QUALIFIER">
   
      <id name="qualifierId" column="QUALIFIER_ID" type="long" >
         <generator class="native" />
      </id>   
      
      <property name="name" type="string">
         <column name="NAME" length="20" not-null="true" />
      </property>
      
      <property name="value" type="string">
         <column name="VALUE" length="250" />
      </property>       

   </class>

</hibernate-mapping>


EntityManagerFactory and TransactionManager config
Code:
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">

<!-- use  org.springframework.orm.jpa.vendor.HibernateJpaDialect and org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter-->

</bean>

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
   <property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>


The query I'm trying to run : just get all the qualifiers from my DB
Code:
CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaQuery<Qualifier> cq = cb.createQuery(Qualifier.class);
Root<Qualifier> qualifRoot = cq.from(Qualifier.class);
cq = cq.select(qualifRoot);
List<Qualifier> results = entityManager.createQuery(cq).getResultList();


The exception thrown when I test my query
Code:
java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: unexpected token: null near line 1, column 29 [select generatedAlias0 from null as generatedAlias0]
   at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1201)
   at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1147)
   at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:324)
   at org.hibernate.ejb.criteria.CriteriaQueryCompiler.compile(CriteriaQueryCompiler.java:227)
   at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:441)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:240)
   at $Proxy13.createQuery(Unknown Source)
   at com.imgt.ligmdb.dao.prod.impl.ImgtQualifierDAOImpl.getReferenceDateRange(ImgtQualifierDAOImpl.java:41)
   at com.imgt.ligmdb.dao.prod.ImgtQualifierDAOTest.getReferenceDateRange(ImgtQualifierDAOTest.java:42)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)
   at org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98)
   at org.unitils.UnitilsJUnit4TestClassRunner$TestListenerInvokingMethodRoadie.runTestMethod(UnitilsJUnit4TestClassRunner.java:174)
   at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
   at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:87)
   at org.unitils.UnitilsJUnit4TestClassRunner$TestListenerInvokingMethodRoadie.runBeforesThenTestThenAfters(UnitilsJUnit4TestClassRunner.java:156)
   at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
   at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
   at org.unitils.UnitilsJUnit4TestClassRunner.invokeTestMethod(UnitilsJUnit4TestClassRunner.java:95)
   at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
   at org.unitils.UnitilsJUnit4TestClassRunner.access$000(UnitilsJUnit4TestClassRunner.java:44)
   at org.unitils.UnitilsJUnit4TestClassRunner$1.run(UnitilsJUnit4TestClassRunner.java:62)
   at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
   at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
   at org.unitils.UnitilsJUnit4TestClassRunner.run(UnitilsJUnit4TestClassRunner.java:68)
   at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
   at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.hibernate.hql.ast.QuerySyntaxException: unexpected token: null near line 1, column 29 [select generatedAlias0 from null as generatedAlias0]
   at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:54)
   at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:47)
   at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:82)
   at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:284)
   at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:182)
   at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
   at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
   at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
   at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:124)
   at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156)
   at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135)
   at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1770)
   at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:306)
   ... 35 more


My problem is that the query have a null FROM clause !
From what I understood, reading Spring/Hibernate code, the generated SQL query take the name of the table it uses in FROM clause from the EntityType.jpaEntityName property and this jpaEntityName is set when PersistentClass objects are build when context is loaded but I can't figure out why in my case this property is never set
Am I missing a step in my config or my mapping ?
Any other idea ?

I'm really stuck so thanks a lot in advance if you get me out of there :-)


Top
 Profile  
 
 Post subject: Re: "select a from null as a" with CriteriaQuery
PostPosted: Mon Mar 21, 2011 4:37 am 
Newbie

Joined: Fri Oct 28, 2005 4:30 am
Posts: 16
up !


Top
 Profile  
 
 Post subject: Re: "select a from null as a" with CriteriaQuery
PostPosted: Wed Apr 13, 2011 4:52 am 
Newbie

Joined: Wed Apr 13, 2011 4:50 am
Posts: 3
I have the same problem, Could you please tell me how do you solved that?


Top
 Profile  
 
 Post subject: Re: "select a from null as a" with CriteriaQuery
PostPosted: Tue May 17, 2011 10:55 am 
Newbie

Joined: Fri Oct 28, 2005 4:30 am
Posts: 16
Hi,
Sorry I didn't see your post before. Hope you find a solution since april...
Actually, when using XML mapping, some "new" attributes (for JPA implementation) in hibernate classes are set when using annotation mapping but not when using xml mapping.
As theses attributes are used to build SQL queries whatever the type of mapping you use, it looked like a bug to me, so I fixed it in Hibernate directly.
I posted the patch on Hibernate JIRA http://opensource.atlassian.com/projects/hibernate/browse/HHH-6100
As people on JIRA didn't answer me yet, I don't know if the way I fixed it is good but it works well for me.
Hope this helps


Top
 Profile  
 
 Post subject: Re: "select a from null as a" with CriteriaQuery
PostPosted: Wed May 18, 2011 12:57 am 
Newbie

Joined: Wed Apr 13, 2011 4:50 am
Posts: 3
Yes, I solved that problem with the help of http://web.archiveorange.com/archive/v/v12Ldzxk09gvWc1UHvpX.

Any way thanks man!!!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.