-->
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: Annotated parent - child problem
PostPosted: Thu Feb 14, 2008 6:37 am 
Newbie

Joined: Tue Jun 26, 2007 3:08 am
Posts: 10
Hello,
I have a class like this:
Code:
@Entity
public class Category {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
 
@ManyToOne(fetch=FetchType.EAGER)
@JoinColumn(name="parent_id")
@Cascade(org.hibernate.annotations.CascadeType.SAVE_UPDATE)
private Category parent;

@OneToMany(mappedBy="parent", fetch=FetchType.EAGER)
@Cascade(org.hibernate.annotations.CascadeType.SAVE_UPDATE)
@IndexColumn(name="list_id")
private List<Category> children = new ArrayList<Category> ();
}

when I put some categories on it by creating new one, and adding children, I got only inserts e.g.:
Hibernate: insert into Category (id, parent_id) values (null, ?, ?, ?, ?)
Hibernate: call identity()
Hibernate: insert into Category (id, parent_id) values (null, ?, ?, ?, ?)
Hibernate: call identity()
[... and more]
but parent_id remains null, there is no updates after saving entity, collection lost its parent, and also parent field remains null. What is wrong with such annotations, I think that generated id could be responsible for nulls, but shouldn't be launched updates after inserting collection?

Database memory HSQL.

best regards,
Adr

Solved I forgot to setParent on category, that's why it isn't assign ids :( Annotations are good for this problem.


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.