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.