-->
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.  [ 1 post ] 
Author Message
 Post subject: Inserts not done in topological order...
PostPosted: Tue Mar 06, 2007 2:57 pm 
Newbie

Joined: Tue Dec 12, 2006 2:07 pm
Posts: 8
Hi All,

I'm having troubles when persisting entities tightly related. I have three entities:

ActiveItem

public class ActiveItem extends Entity {
@ManyToOne(cascade = {CascadeType.ALL})
@JoinColumn(name = "logicalitemid")
private LogicalItem logicalItem;

...
}


LogicalItem

public final class LogicalItem extends Entity {
@OneToMany(mappedBy = "logicalItem",
fetch = FetchType.LAZY,
cascade = {CascadeType.ALL})
private Set<ActiveItem> activeItems = new HashSet<ActiveItem>();

@OneToOne(fetch = FetchType.LAZY,
mappedBy = "logicalItem",
cascade = {CascadeType.ALL})
private LatestView latestView;

...
}


LatestView

public class LatestView extends View {
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "logicalitemid")
private LogicalItem logicalItem;

@OneToOne(fetch = FetchType.LAZY,
cascade = {CascadeType.PERSIST})
@JoinColumn(name = "itemid")
private ActiveItem activeItem;

...
}


(only the relevant parts are shown here).

My problem is when I save a new activeItem the SQL generated is

insert into logicalitems (ownerid, id) values (?, ?)
insert into items_views (policyid, logicalitemid, itemid, id) values (?, ?, ?, ?)


and fails since items_views has a foreign key reference on active item, which does not have an id yet since it wasn't persited... How can I tell Hibernate to save those three entities in reverse topological order?

Thanks! Pascal


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

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.