Hibernate version: Hibernate 3.2.5.GA, Hibernate Annotations 3.3.0 GA, Spring 2.0.x.
i'm trying to map an
One-to-Many with a composite key on the many. The mapping I've used below doesn't seem to work. Using the hbm files I'm able to map the Alias as a composite key, but it doesn't make any sense to create a whole different class for the composite key if in fact the class is a composite key.
Code:
@Entity
public class Person implements Serializable {
@Id
private Integer personId;
@OneToMany(mappedBy="patient")
private Collection<Alias> aliases;
// getters and setters
}
@Entity
public class Alias implements Serializable {
@Id
private Integer personId;
@Id
private Enum aliasType;
@Id
private String value;
// getters and setters
}
Code:
+------------------------------+
| Person |
+------------------------------+
| personId: Integer(PK) |
| aliases:Collection |
+------------------------------+
|
|
+------------------------------+
| Alias |
+------------------------------+
| personId: Integer(PK) |
| aliasType: Enum(PK) |
| aliasValue: String(PK) |
+------------------------------+
I have thought of mapping the class as if the alias type and value columns were not keys, however, this could potentially run into problems.
If anyone has any thoughts I am open for suggestions. Thanks.