-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: multiple updates in OneToMany relation
PostPosted: Wed Nov 05, 2008 8:38 am 
Beginner
Beginner

Joined: Wed Apr 23, 2008 2:00 pm
Posts: 20
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??


Top
 Profile  
 
 Post subject: solved!
PostPosted: Thu Nov 06, 2008 8:58 am 
Beginner
Beginner

Joined: Wed Apr 23, 2008 2:00 pm
Posts: 20
I find a solution.. i've modified my AssignedActivities class :

@Id
@Column (name = "PACT_ID", nullable=false)
private Integer pactId;

And that's it, now is working.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.