Hi,
I woud like to know why my associated classes are forced to be persisted when I use @IdClass ?
My classes :
Code:
@Entity
@IdClass(ScoreId.class)
public class Score implements Serializable {
...
@Id
@ManyToOne(cascade = {})
@JoinColumn(name = "id_ticket", insertable = false, updatable = false)
@Cascade({}) // I don't want any cascade !
@NotNull
public Ticket getTicket() {
return ticket;
}
@Id
@ManyToOne(cascade = {})
@Cascade({})
@JoinColumn(name = "id_user", insertable = false, updatable = false)
@NotNull
public User getUser() {
return user;
}
public int getScore() {
return score;
}
}
Code:
public class ScoreId implements Serializable {
private Integer ticket;
private Integer user;
// ... getter, setter, equals and hashcode ...
Code:
@Entity
public class Ticket implements Serializable {
@Id
@GeneratedValue
@Column(name = "id_ticket")
public Integer getIdTicket() {
return idTicket;
}
}
Code:
@Entity
public class User implements Serializable {
// ...
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id_user")
public Integer getUserId() {
return userId;
}
When I'm saving Score object, my Ticket and User are persisted. I don't specified any cascade, so why ?
My test code :
Code:
@Test
public void testSave() {
User user = userDAO.findById(2);
assertNotNull(user);
Ticket ticket = ticketDAO.findById(6);
assertNotNull(ticket);
Score score = new Score();
score.setScore(3);
score.setTicket(ticket);
score.setUser(user);
scoreDAO.save(score); // using hibernate.Session.saveOrUpdate
}
Thanks,
(and sorry for my english...)
Dush