Hi,
I am trying to create a relation between my classes
Cell and
TeamPoint using Hibernate. Each
Cell is supposed to be referred to by many
TeamPoints.
When i create a
Cell consisting of a list of e.g. two TeamPoints, the
Cell is correctly created in the database, but the
TeamPoints are just created with their cellId=NULL. I thought that this should be updaed by Hibernate after insertion?
The important parts of the two classes is shown below. I have left out unrealted fields, getters and setters, from both classes.
Cell:
Code:
@Entity
@Table(name = "cell")
public class Cell implements Serializable{
@Id @GeneratedValue(strategy = GenerationType.AUTO)
int id;
@OneToMany(
mappedBy="cellId",
cascade = CascadeType.ALL,
fetch = FetchType.EAGER,
targetEntity=TeamPoint.class
)
@org.hibernate.annotations.Cascade(value = org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
@OrderBy("teamId")
List<TeamPoint> teamPoints = new LinkedList<TeamPoint>();
public Cell() {
}
public List<TeamPoint> getTeamPoints() {
return teamPoints;
}
@OneToMany
@JoinColumn (name = "cellid")
public void setTeamPoints(List<TeamPoint> teamPoints) {
this.teamPoints = teamPoints;
}
}
TeamPoint:
Code:
@Entity
@Table(name = "teamPoints")
public class TeamPoint implements Serializable {
@Id @GeneratedValue(strategy = GenerationType.AUTO)
int id;
@ManyToOne(
cascade = {CascadeType.PERSIST, CascadeType.MERGE},
targetEntity=Cell.class
)
@JoinColumn (name="cellId", nullable = false, updatable = false, insertable = false)
Cell cellId;
int teamId;
float points;
public TeamPoint() {
}
}