I'm new to Hibernate and Annotations. I'm reading the Java Persistance with Hibernate, a great introduction, but I still can't 'solve' my problem..
I have two tables:
Code:
item(id, name, description_id)
description(id, language, description)
Now I would like to get an item record with the description in the correct language. In SQL it would be like:
Code:
SELECT i.name, d.description FROM item i LEFT OUTER JOIN description d ON i.description_id=d.id WHERE i.id=? AND d.language=?
So I've created two classes:
Code:
@Entity
public class Item() {
@Id
@GeneratedValue
private Long id;
private String name;
@JoinColumn(name = "description_id")
private Description description;
..
}
@Entity
public class Description() {
@Id
@GeneratedValue
private Long id;
private String language;
private String description;
..
}
In my HQL query I can't specify the join and the column d.id is not available. I'm reading chapter 8 now... but maybe someone can help me.
First thing that's not correct is the Description class, the "id" is not unique, the combination of "id" and "language" is unique, so I should use a CompositeId?? Is it possible with annotations or should I change my strategy?