If mapping the Nickname table is not an option, you could map the property using a secondary table to join in the nickname value. If you're using annotations, it would look something like this:
Code:
@Table(name="person_table")
@SecondaryTables({
@SecondaryTable(name="nickname_table", pkJoinColumns={
@PrimaryKeyJoinColumn(name="person_id", referencedColumnName="id")
),
})
public class Person {
@Id
@Column(name="person_id")
private int Id;
@Column(table="nickname_table",name="nickname)
private String nickName;
}
N ote: my syntax maybe off slightly, but this is the general idea. What's going on here is that we're joining in both the person_table & nick_name table into 1 class. This way, nickname appears as a property of the Person and you HQL can be written as if the value was part of the person_table. So once you have that, you could write an HQL query such that:
Code:
find( "from Person as p where p.nickName = 'tom')
Hibernate will generate the proper SQL to join the 2 tables together. This type of this is also possible (and a bit more clear IMHO) using the XML mappings. Have a look at the <join> element in the docs for more details and some of the Hibernate JUnits.
Another option is to use a complete native SQL loader query or a formula.
Ryan-