-->
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.  [ 2 posts ] 
Author Message
 Post subject: createNamedQuery using part of composite key.
PostPosted: Thu Feb 26, 2009 12:02 pm 
Newbie

Joined: Thu Feb 26, 2009 11:33 am
Posts: 1
Hi,


I am trying to create a simple namedQuery where the qualifier is a part of a composite key using JPA.

Here's how I defined the primary key class (composite key):


public class LocationGroupKey implements Serializable {

public long childLocationId;

public long parentLocationId;

public LocationGroupKey() {

}

//... the rest of the code omitted for brevity.

Here's how I defined the entity class:

@Entity
@Table(name = "location_group")

@NamedQuery(name = LocationGroupEntity.QUERY_FIND_CHILD_LOCATION_BY_PARENT_LOCATION, query = "select l from LocationGroupEntity l where l.parentLocationId = :parentLocationId and l.isActive = true")

@IdClass(LocationGroupKey.class)

public class LocationGroupEntity implements Serializable {


public static final String QUERY_FIND_CHILD_LOCATION_BY_PARENT_LOCATION = "LocationGroupEntity.findChildLocationByParentLocation";

@Id
@Column(name = "parent_loc_cd")
private long parentLocationId;

@Id
@Column(name = "child_loc_cd")
private long childLocationId;

//... the rest of the code omitted for brevity.


The code that will create the query worked fine, but when I tried to get the result, it threw the following exception:

Hibernate: select locationgr0_.childLocationId as childLoc1_9_, locationgr0_.parentLocationId as parentLo2_9_, locationgr0_.active_ind as active3_9_ from LOCATION_GROUP locationgr0_ where locationgr0_.parentLocationId=? and locationgr0_.active_ind=1
0 [btpool3-1] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 904, SQLState: 42000
15 [btpool3-1] ERROR org.hibernate.util.JDBCExceptionReporter - ORA-00904: "LOCATIONGR0_"."PARENTLOCATIONID": invalid identifier

Why doesn't parentLocationId recognized? I put @Column to indicate that that the database column has a different name (the real field name = parent_loc_cd). Is there something that I miss in here?

Any suggestions on what to look for will be appreciated.

Thank you,

-Dhalsim


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 27, 2009 4:01 am 
Expert
Expert

Joined: Fri Jan 30, 2009 1:47 am
Posts: 292
Location: Bangalore, India
This seems to be a bug. See http://opensource.atlassian.com/project ... se/ANN-685

Please vote for it. If you feel this should be fixed.

A workaround they suggest is to annotate the IdClass attributes.

_________________
Regards,
Litty Preeth


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