Hibernate version: 3.2.5.ga
Hi! Currently I need to have 3 attributes of one class (
Researcher) in another entity (
Thesis). A code snippet:
Code:
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="ths_id") private Integer thesisID;
...
@OneToOne(targetEntity=Researcher.class)
@JoinColumn(name="ths_auth", referencedColumnName="rese_id")
private Researcher author;
@OneToOne(targetEntity=Researcher.class)
@JoinColumn(name="ths_dire", referencedColumnName="rese_id")
private Researcher director;
// @OneToOne(targetEntity=Researcher.class)
// @JoinColumn(name="ths_codir",referencedColumnName="rese_id", nullable=true)
// private Researcher coDirector;
When I display a list of researchers for each attribute in my
jsp to select one and set it into the entity (I'm using SpringMVC), the behaviour of Hibernate is (in case of setting only 2 of the 3 elements):
- Insert into
thesis table an entry only with
one of the attributes setted,
null in all other fields minus primary key).
- (submit processing in controller and invoke facade to insert entity)
- Throwned exception "identifier of an instance of es.udc.lbd.portal.model.thesis.entity.Thesis was altered from 2 to null" (for example).
¿Could be a problem the existence of 3 elements of the same entity mapped with
@OneToOne? Perhaps you could propose making a collection of elements and fill it with this 3 attributes, but I need to differenciate each one from the others.
Explanation: The "roles" needed for the entities:
- Author
- Director
- CoDirector
So, due to this, the collection is not a good solution.
Can anyone help me about this?