Hibernate version: 2.1.6
Name and version of the database you are using: Oracle 9i
I have an object with a composite-id and I have the composite-id as a seperate class. I can load the instance by giving whole composite-id attributes but I want to retrieve the row with a maximum of one of the key columns.
Example: (from Hibernate references)
User class has a field UserID class which has two fields (userName, organizationUnit) and these are composite-id in the User.xml like this.
<class name="User" table="USER">
<composite-id name="userId" class="UserId">
<key-property name="userName" column="USERNAME"/>
<key-property name="organizationId" column="ORGANIZATION_ID"/>
</composite-id>
<property ...
...
</class>
The UserID class looks like :
public class UserId extends Serializable
{
private String username;
private String organizationId;
public UserId(String username, String organizationId)
{
this.username = username;
this.organizationId = organizationId;
}
// Getters...
public boolean equals(Object o) {....}
public int hashCode() {....}
}
I can load an instance with the code:
UserId id = new UserId("john", 42);
User user = (User) session.load(User.class, id);
but I want to query something like this: (here is the question)
max(organizationId) from User where userName like "john"
I know sample is nonsense but my problem is something like that.
Note: I searched the FAQ, I hope I didn't miss a post like that...
_________________ thanks
|