-->
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.  [ 4 posts ] 
Author Message
 Post subject: possible bug in using the TYPE JPQL keyword ?
PostPosted: Thu Nov 14, 2013 11:17 am 
Newbie

Joined: Thu Nov 14, 2013 11:08 am
Posts: 3
Hi,

I tried to use the TYPE keyword in hibernate with the following test:


Code:
@Test
   public void exampleSelectingRegularEmployeesUsingTypeKeyword(){
      List<RegularEmployee> regularEmployees = createRegularEmployees(2);
      List<ContractorEmployee> contractorEmployees = createContractorEmployees(3);

      
      em.getTransaction().begin();
      for(RegularEmployee e:regularEmployees){
         em.persist(e);
      }
      for(ContractorEmployee e:contractorEmployees){
         em.persist(e);
      }
      em.getTransaction().commit();
      
      Query query = em.createQuery("SELECT e FROM Employee WHERE TYPE(e)<>RegularEmployee");
      @SuppressWarnings("unchecked")
      List<RegularEmployee> regularEmployeesReturned = query.getResultList();
      assertEquals(regularEmployees.size(), regularEmployeesReturned.size());
   }


(the test can be found in the EmployeeInheritanceTest class, here:

https://github.com/scutaru/trainingjpa/blob/master/trainingjpa/src/test/java/ro/scutaru/trainingjpa/employee/domain/EmployeeInheritanceTest.java

The test fails with the following exception:

Code:
java.lang.NullPointerException
   at org.hibernate.hql.internal.ast.tree.MethodNode.typeDiscriminator(MethodNode.java:86)
   at org.hibernate.hql.internal.ast.tree.MethodNode.resolve(MethodNode.java:67)
   at org.hibernate.hql.internal.ast.HqlSqlWalker.processFunction(HqlSqlWalker.java:1008)
   at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.functionCall(HqlSqlBaseWalker.java:2612)
   at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1338)
   at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:4426)
   at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:3922)
   at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2076)
   at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:794)
   at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:595)
   at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:299)
   at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:247)
   at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:250)
   at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:185)
   at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:138)
   at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:105)
   at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
   at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:168)
   at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:221)
   at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:199)
   at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1784)
   at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:291)
   at ro.scutaru.trainingjpa.employee.domain.EmployeeInheritanceTest.exampleSelectingRegularEmployeesUsingTypeKeyword(EmployeeInheritanceTest.java:49)
   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.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
   at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
   at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
   at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
   at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
   at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
   at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
   at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
   at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
   at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
   at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
   at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
   at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
   at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
   at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
   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)


Thank you.


Top
 Profile  
 
 Post subject: Re: possible bug in using the TYPE JPQL keyword ?
PostPosted: Wed Nov 20, 2013 6:18 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Can it be that your persistent class Employee does not have a discriminator column at all?
Can you please add the sources of Employee and its subclasses to your github branch?


Top
 Profile  
 
 Post subject: Re: possible bug in using the TYPE JPQL keyword ?
PostPosted: Thu Nov 21, 2013 4:19 am 
Newbie

Joined: Thu Nov 14, 2013 11:08 am
Posts: 3
Sorry for the late response..

The classes were already committed on Github:

https://github.com/scutaru/trainingjpa/tree/master/trainingjpa/src/main/java/ro/scutaru/trainingjpa/employee/domain

Code:
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "EMP_TYPES")
public class Employee {
....


As you can see above there is a discriminator column specified in the Employee entity, so this is not the reason..


Top
 Profile  
 
 Post subject: Re: possible bug in using the TYPE JPQL keyword ?
PostPosted: Thu Nov 21, 2013 4:24 am 
Newbie

Joined: Thu Nov 14, 2013 11:08 am
Posts: 3
I also opened a ticket..

https://hibernate.atlassian.net/browse/HHH-8701


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.