Hibernate version: 2.1
Given the following class:
Code:
public class Building implements Serializable{
private Integer id;
private String name;
private Type type;
....
}
where Type is defined as
Code:
public class Type implements Serializable{
private Integer id;
private String name;
.....
public Type(Integer id){
this.id = id;
}
}
I want to create a new Building instance given an input form..Can I do the following to set its Type object:
Code:
public Building(BuildingForm form){
name = form.getName();
//assuming that a Type instance with form.getTypeId() already
//exists in the database.
type = new Type(form.getTypeId());
}
I think the other, and probably better, way of accomplishing the same thing would be to retrieve the Type object with form.getTypeId() and set it that way. Is this way definitely wrong?
Thanks,
Cagan