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
}
|