Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
[b]Hibernate version:3
Hello,
I'm using annotations and I have 3 classes like this :
@Entity
@Table(name = "PROJECTS")
public class Project implements IsSerializable {
@Id
@Column (name= "PROJ_ID")
private Integer id;
@Column (name= "PROJ_DESC")
private String descripcion;
@Column (name= "PROJ_DET")
private String det;
@OneToMany
@JoinColumn (name = "PROJ_ID")
@Cascade ({CascadeType.ALL,
CascadeType.DELETE_ORPHAN})
private List<Activity> activities;
...
}
@Entity
@Table (name="PROJECT_ACTIVITIES")
public class Activity implements IsSerializable{
@Id
@Column(name="PACT_ID")
private Integer id;
@Column(name="PACT_DESC")
private String desc;
@Column (name ="STATE")
private Integer state;
@Column (name ="PROJ_ID")
private Integer idProject;
@Column (name ="PACT_DUE_DATE")
private Date dueDate;
@OneToMany
@JoinColumn (name = "PACT_ID")
@Cascade({CascadeType.ALL,CascadeType.DELETE_ORPHAN})
private List<AssignedActivities> assignedTo;
...
}
@Entity
@Table(name = "ASSIGNED_ACTIVITIES")
public class AssignedActivities implements IsSerializable {
@Column (name = "CONS_ID")
private Integer consId;
@Id
@Column (name = "PACT_ID")
private Integer pactId;
@Column (name = "TYPE")
private Integer type;
...
}
In my java code I add a new AssignedActivities to an Activity. When I execute a session.update(activity) in m'y console i'm having
Hibernate: select assignedac_.PACT_ID, assignedac_.ASG_EST_TIME as ASG2_8_, assignedac_.CONS_ID as CONS3_8_, assignedac_.TYPE as TYPE8_ from ASSIGNED_ACTIVITIES assignedac_ where assignedac_.PACT_ID=?
Hibernate: insert into ASSIGNED_ACTIVITIES (ASG_EST_TIME, CONS_ID, TYPE, PACT_ID) values (?, ?, ?, ?)
Hibernate: update PROJECT_ACTIVITIES set PACT_DESC=?, PACT_DUE_DATE=?, PROJ_ID=?, STATE=? where PACT_ID=?
Hibernate: update ASSIGNED_ACTIVITIES set PACT_ID=null where PACT_ID=?
Hibernate: update ASSIGNED_ACTIVITIES set PACT_ID=? where PACT_ID=?
And in my database I have a new record in ASSIGNED_ACTIVITIES but width a PACT_ID empty.. so i imagine that first the correct record is inserted , but why is after updating this record width PACT_ID=null??