-->
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: @AccessType("field") on @MappedSuper doesn't inher
PostPosted: Mon May 15, 2006 3:43 am 
Beginner
Beginner

Joined: Thu Nov 06, 2003 7:27 pm
Posts: 30
Location: Minneapolis, MN, USA
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....


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.