-->
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: search on composite key
PostPosted: Mon Dec 12, 2005 4:41 pm 
Newbie

Joined: Mon Dec 12, 2005 4:29 pm
Posts: 1
Location: Washington DC
I have a table that has a composite primary key

create table AuditLog
{
usrId varchar(16) not null,
lastUpdTm datetime not null,
msg varchar(266) null,
action int null,
....
constraint AuditLog_PK
PRIMARY KEY NONCLUSTERED (usrId, lastUpdTm)
}

Say I need to search all log record of a particular user.

So I would like to do something like this:

from AuditLog where usrId = 'abc123'


But this does not work because usrId is part of the composite key.

My question: how can get this done using Hibernate?

Any suggestion is greatly appreciated!


Top
 Profile  
 
 Post subject: id
PostPosted: Mon Dec 12, 2005 6:04 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
components of composite ID can be addressed with using id prefix of real ID property name,
so lets suppose the AuditLog object has property ‘key’ of AuditLogPK type.

Then our hql may look like
From AuditLog a where a.id.userId =:uid

Or
From AuditLog a where a.key.userId =:uid

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


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.