-->
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: Cascading persist does not work on ManyToOne association
PostPosted: Thu Feb 19, 2009 1:00 pm 
Beginner
Beginner

Joined: Wed Apr 05, 2006 5:01 am
Posts: 20
Hi guys!

I have a problem with a cascading save that is performed in the wrong order.

Hibernate version:3.3.1.GA

Mapping documents:

Code:
@Entity
@Table(name = "psb")
public class Psb implements Serializable {

@EmbeddedId
private PsbId psbId;

@JoinColumns(value = {
       @JoinColumn(name = "snr", insertable = false, updatable = false),
       @JoinColumn(name = "psbnr", insertable = false, updatable = false) })
@ManyToOne(cascade = CascadeType.ALL)
private ExtraData extraData;
}

Code:
@Embeddable
public class PsbId Serializable {


@Column(name = "snr", nullable = false)
private Long snr;
@Column(name = "psbnr", nullable = false)
private Long psbnr;

}


Code:
@Entity
@Table(name = "extradata")
public class ExtraData implements Serializable {

@EmbeddedId
private PsbId psbId;

}


Code between sessionFactory.openSession() and session.close():

Psb psb = new Psb();
PsbId psbId = new PsbId();
psbId.setSnr(666);
psbId.setPsbnr(1);

ExtraData data = new ExtraData();
data.setPsbId(psbId);
psb.setExtraData(data);

entityManager.persist(psb);


--> this results in Hibernate trying an INSERT on the second extradata table
before inserting into the psb table, which violates foreign key constraints.
Why does the CascadeType.ALL annotation i put on the ManyToOne mapping
does not enable a cascading save in the correct order? Have i done any mistakes in my configuration?

Many thanks for any help and suggestions!

-lasse


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 20, 2009 11:59 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Wrong forum! Only Validator, Search or Shards questions here. Try posting your question on the main Hibernate User forum.


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.