-->
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: Using an entity id not the entity as a reference
PostPosted: Thu Oct 18, 2007 2:13 pm 
Newbie

Joined: Tue Dec 19, 2006 7:23 pm
Posts: 4
I have a folder hierarchy I am mapping.
A Folder contains Items, mapped as a list of ItemBeans.
A Folder is a subclass of an Item.
An Item has a reference to the folder it is in, hopefully mapped by parent_id column.

I want the itemBean to contain the id of the parent, not the parentBean,
to help break circular reference issues.

Is this possible?
Below are the relavent annotations.

Is there a way in @ManyToOne to specify that I want to use the id of the FolderBean.class?


I get a IllegalArgumentException: object is not an instance of declaring class when setting the parent.

Below are the relevant annotations.

thanks in advance,
BobBobBob


ItemBean

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "item_id")
public String getId() {
return id;
}

@ManyToOne(targetEntity = com.example.model.FolderBean.class)
@JoinColumn(name = "parent_id")
public String getParentId() {
return (String) getAttr(ATTR_PARENT_ID);
}

FolderBean extends ItemBean
/**
* Return a list of the items in this folder.
*
* @return a List of items in this folder
*/
@OneToMany(mappedBy = "parentId")
@OrderBy("name")
public List<ItemBean> getItems() {
return itemBeans
}


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.