-->
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: Can I restrict a CollectionOfElements with a where clause?
PostPosted: Wed May 27, 2009 1:25 pm 
Newbie

Joined: Mon Apr 14, 2008 11:24 am
Posts: 5
Hi,
I am using hibernate annotations. I can't modify the table definitions.

I have the following tables:
CLIENT with columns (CLIENT_ID, NAME, ADDRESS).
QUEUE with columns (CLIENT_ID, QNAME, IPADDRESS, ACTIVE)

A client has multiple queues, but each queue has multiple IPADDRESSes, therefore there may be multiple records in QUEUE with the same QNAME -but different IPADDRESS).

I don't need to maintain the QUEUE table; for my application this is a read-only table.

I need to get the different queue names available to a client.
In SQL, this would be
SELECT DISTINCT QNAME FROM QUEUE WHERE CLIENT_ID=? AND ACTIVE='true'

I am trying to map this to my Client class. I would like to have a get method as shown below:

Code:
@Entity
class   Client  {

  Set<String> getQueueNames() {
       return queueNames;
  }
}


I think I could achieve this by:

Code:
@Entity
class   Client  {
  ...
  @CollectionOfElements
  @JoinTable(name="QUEUE",
                  joinColumns= { @JoinColumn(name="CLIENT_ID") })
  @Column(name="QNAME", nullable=false)
  private Set<String> queueNames;

   ...
   Set<String> getQueueNames() {
       return queueNames;
   }
   ...
}

I am assuming that I won't get duplicates since "queues" is defined as a Set<String>; therefore I should get the equivalent to DISTINCT from SQL, right?
but where would I put the WHERE clause to filter for only active records?

Any other way to achieve what I want?

Thanks in advance.


Top
 Profile  
 
 Post subject: Re: Can I restrict a CollectionOfElements with a where clause?
PostPosted: Wed May 27, 2009 4:42 pm 
Newbie

Joined: Mon Apr 14, 2008 11:24 am
Posts: 5
@CollectionOfElements
@JoinTable(name="QUEUE",
joinColumns = { @JoinColumn(name="client_id") })
@Where(clause="Active='Y'")
@Column(name="IPADDRESS", nullable=false)


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.