Hi all,
I tried to create entity which can be recursively pointing to instances of same
type. I want to use it for representing product categories navigation menu:
- Computers
- Laptops
- Cables
- ...
- Cameras
- Digital
- Cards
- MMC
- SD
- XD
- ...
Following entity I can use in Hibernate EM in J2SE without problems but on
GlassFish I am experiencing problems on deployment (see below).
Entity:
---%<---
package foo.entity;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.*;
@Entity
public class Category {
private Long id;
private String name;
private Category parent;
private List<Category> children;
public Category() {
children = new ArrayList();
}
@Id(generate = GeneratorType.AUTO)
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@ManyToOne()
public Category getParent() {
return parent;
}
public void setParent(Category parent) {
this.parent = parent;
}
@OneToMany(mappedBy="parent", cascade={CascadeType.ALL})
public List<Category> getChildren() {
return children;
}
public void setChildren(List<Category> children) {
this.children = children;
}
}
---%<---
GlassFish exceptions:
---%<---
Exception [TOPLINK-48] (Oracle TopLink Essentials - 10g release 4 (10.1.4.0.0)
(Build 051215Dev)): oracle.toplink.essentials.exceptions.DescriptorException
Exception Description: Multiple writable mappings exist for the field
[CATEGORY.ID]. Only one may be defined as writable, all others must be
specified read-only.
Mapping: oracle.toplink.essentials.mappings.OneToOneMapping[parent]
Descriptor: RelationalDescriptor(foo.entity.Category --> [DatabaseTable(CATEGORY)])
---%<---
Any idea, what's the problem?
-M