Hi,
I have two entity classes listed at end of this post, they have referential
integrity in the table level. in a page's onActivate a new Usr is created,
then it is passed to a service where a MsgSubject is created and its usr is
set to the instance of Usr created in the page, but this will always trigger
a referential constraint violation that Usr does not exist in the table:
simplified code:
@Inject private MyService myService;
// code #1
@CommitAfter
public Class onActivate(String id) {
Usr usr = new Usr();
session.save(usr);
myService.addMsgSubj(usr); // new usr does not exist in
the table
exception
}
To solve the above problem, I remove the c3p0 pooling from hibernate
configuration, it works, that means the code is ok, it's just this hibernate
pooling that make the newly added usr not visible to the others even they
are in the same transaction.
putting back the c3p0 pooling and added a commit solve the problem:
// code #2
@CommitAfter
public Class onActivate(String id) {
Usr usr = new Usr();
session.save(usr);
sessionManager.commit(); // this make the
myService.addMsgSubj(usr);
}
is it a must to commit so that objects are visible to services even they
are in the same transaction? any idea?
Thanks
p.s. actually code #1 works if I did not do a commit in a dispatcher:
public boolean dispatch(Request request, Response response) throws
IOException {
PageLog log = new PageLog();
sessionManager.getSession().save(log);
sessionManager.commit();
return false;
}
public class Usr {
private Long id;
private List<MsgSubject> messageTopics = new ArrayList<MsgSubject>();
@Id @GeneratedValue
public Long getId() {
return id;
}
@OneToMany(mappedBy="usr")
@OrderBy("date_last desc")
public List<MsgSubject> getMessageTopics() {
return messageTopics;
}
public void setMessageTopics(List<MsgSubject> messageTopics) {
this.messageTopics = messageTopics;
}
}
public class MsgSubject {
private Long id;
private Usr usr;
@Id
@GeneratedValue
public Long getId() {
return id;
}
private void setId(Long id) {
this.id = id;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="usr_id")
public Usr getUsr() {
return usr;
}
public void setUsr(Usr usr) {
this.usr = usr;
}
}
--
View this message in context:
http://www.nabble.com/t5%3A-commit-before-calling-service-if-parent-child-referential-integrity-exists--tp18628394p18628394.html
Sent from the Tapestry - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]