I'm on Hibernate 3.2cr2, annotations 3.2.0cr1.
I have a common supertype for entities. It declares that I'd like field access by default, though I use property access to assign the ID manually:
Code:
@MappedSuperclass
@AccessType("field")
public class DomainObject
{
@Id @AccessType("property")
private long id = 0;
public long getId()
{
if(id == 0)
id = IdFactory.nextId();
return id;
}
private void setId(long id)
{
if(this.id != 0 && this.id != id)
throw new IllegalStateException("id already assigned");
this.id = id;
}
// equals(), hashCode(), and other methods omitted
}
One of its subtypes is (pared down somewhat) as follows:
Code:
@Entity
@Proxy(lazy=false)
public class Category
extends DomainObject
{
public Category getParent()
{ return parent; }
public void setParent(Category newParent)
{
if(parent == newParent)
return;
if(parent != null)
parent.children.remove(this);
if(newParent != null)
newParent.children.add(this);
parent = newParent;
}
public Set<Category> getChildren()
{ return Collections.unmodifiableSet(children); }
@ManyToOne
private Category parent;
@OneToMany(mappedBy="parent")
private final Set<Category> children = new HashSet<Category>();
}
I believe that Category should inherit the AccessType of its supertype. However, I get the following error:
Code:
org.hibernate.MappingException: Could not determine type for: java.util.Set, for columns: [org.hibernate.mapping.Column(children)]
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:266)
at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:253)
at org.hibernate.mapping.Property.isValid(Property.java:185)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:395)
at org.hibernate.mapping.RootClass.validate(RootClass.java:192)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1021)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1206)
at net.innig.framework.persistence.hibernate.HibernateHelper.getSessionFactory(HibernateHelper.java:60)
... 23 more
Adding the apparently redundant @AccessType("field") fixes the problem. It seems that the AccessType of the MappedSuperclass isn't getting applied to the subclass properly.
Is this intended behavior, and simply a misleading error message? Or is it a potential bug?
If the latter, I will happily provide a complete test case. But I didn't want to take the time to prepare one if I'm just making a stupid mistake....