-->
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.  [ 3 posts ] 
Author Message
 Post subject: JPA 2 CriteriaQuery Using ID columns throws Null Pointer EX
PostPosted: Thu Jun 24, 2010 2:25 pm 
Newbie

Joined: Thu Jun 24, 2010 2:08 pm
Posts: 1
Im trying to run a basic select record where I assign a value to a pk column
select * from ae_p_pst_c where status_code = "OPEN";
Code:
public class AePPstCPK {
...
@Column(name = "status_code")
public String getStatusCode() {
   return (String)attributes[0].getValue();

...}

-------------------
@Entity
@Table(name = "ae_p_pst_c")
@IdClass(AePPstCPK.class)
public class AePPstCDTO {
...
@Id
@Column(name = "status_code", nullable = false , length = 20)
public String getStatusCode() { 
   return (String) getAttribute(AePPstCAttributeName.STATUS_CODE).getValue();   
}       
...
}


Code:
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<AePPstCDTO> cq = cb.createQuery(AePPstCDTO.class);
    Root<AePPstCDTO> aePPstCDTORoot = cq.from(AePPstCDTO.class);
    cq.where(cb.equal(aePPstCDTORoot.get("statusCode"), "OPEN"));   //status Code is a ID column and cant be found in attribute list???



I will get NullpointerException when the code tries to get statusCode from aePPstCDTORoot.
Code:
java.lang.NullPointerException
   at org.hibernate.ejb.criteria.path.AbstractPathImpl.unknownAttribute(AbstractPathImpl.java:110)
   at org.hibernate.ejb.criteria.path.AbstractPathImpl.locateAttribute(AbstractPathImpl.java:218)
   at org.hibernate.ejb.criteria.path.AbstractPathImpl.get(AbstractPathImpl.java:189)


Can anyone tell me how to write the code so that I can access the ID columns in my query
P.S. It works fine if I use a column that is not the pk column.

-Greg


Top
 Profile  
 
 Post subject: Re: JPA 2 CriteriaQuery Using ID columns throws Null Pointer EX
PostPosted: Wed Jan 19, 2011 8:43 am 
Newbie

Joined: Thu Jan 24, 2008 4:45 am
Posts: 13
I have an @Entity, let's name it A and I'm getting NPE as well, when calling get(propertyName) on instance of Root<A>. Type B is @Embeddable and is @Embeeded in A as property named b. Type C is @MappedSupperclass, and B extends C. C has @Temporal property d of type java.util.Date. propertyName, in call to Root<A>.get(propertyName), equals to "b.d" - so using dot notation I'm trying to reference @MappedSuperclass property @Embedded in @Entity via @Embeddable which extends @MappedSuperclass.

If this is not supported, Hibernate should fail earlier, without throwing NPE later. It seems AbstractPathImpl.pathSource is null.

I'm using Hibernate 3.6.0.Final.

Regards,
Stevo.


Top
 Profile  
 
 Post subject: Re: JPA 2 CriteriaQuery Using ID columns throws Null Pointer EX
PostPosted: Wed Apr 06, 2011 10:52 am 
Newbie

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

Did you finally solve your problem, how ?
Thanks


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