-->
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.  [ 3 posts ] 
Author Message
 Post subject: Interface Mapping with Annotations
PostPosted: Tue Apr 19, 2005 5:49 pm 
Newbie

Joined: Tue Apr 19, 2005 11:24 am
Posts: 8
I read over the forums and google'd for a bit, and have been unable to find a solution to my problem for the past couple hours, so hopefully someone can point me in the right direction.

I have an interface (let's call it Blah) that contains a collection of children that are also Blah's. So something like the following:

Code:
@Entity @Inheritance(strategy = InheritanceType.JOINED) public interface Blah extends Serializable {

    Integer getId();
    void setId(Integer value);
    Collection<Blah> getChildren();
    void setChildren(Collection<Blah> children);
...
}


I have an abstract class that implements the "id" functions, with the appropiate annotations:

Code:
@Entity @Inheritance(strategy = InheritanceType.JOINED) public abstract class AbstractBlah implements Blah {

@id(generate = GeneratorType.AUTO) public Integer getId() {...}
    public void setId(Integer value) {...}


I then have another couple abstract classes called ParentAdapter and ChildAdapter. Both of these classes extends the AbstractBlah class, and implement the appropiate getChildren() / setChildren() functionality with the following annotations:


Code:
@Entity @Inheritance(strategy = InheritanceType.JOINED) public abstract class ParentAdapter extends AbstractBlah {

    @OneToMany(targetEntity = "Blah") @AssociationTable(table = @Table(name = "parentChildren"), joinColumns = {@JoinColumn(name = "parent_id")}, inverseJoinColumns = @JoinColumn(name = "child_id")) public Collection<Blah> getChildren() { ... }
    void setChildren(Collection<Blah> children) {...}


The problem that I have encountered is:

Code:
MappingException: Association references unmapped class: Blah


My hibernate.cfg.xml file looks like the following (minus the database-specific stuff):

Code:
<hibernate-configuration>
    <session-factory>
...
        <mapping class="a.b.c.AbstractBlah"/>
        <mapping class="a.b.c.ParentAdapter"/>
        <mapping class="a.b.c.ChildAdapter"/>
        <!-- Some more classes are mapped...the actual concrete ones -->
...
    </session-factory>
</hibernate-configuration>


I haven't included mapping the Blah interface because I was getting a null pointer exception (and may be part of the reasoning to my problem). In AnnotationBinder.java at line 257, it has the line:

Code:
Class superClass = annotatedClass.getSuperclass();


Interfaces do not have superclasses, and therefore the reason for the null pointer exception. This may be a bug in the hibernate annotations.

I am new to using Hibernate / Hibernate Annotations, so there may have been something that I missed in the documentation. I just could not find anything in the documentation that covered the usage of java interface's and mapping them properly.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 19, 2005 6:19 pm 
Newbie

Joined: Tue Apr 19, 2005 11:24 am
Posts: 8
As a follow-up, I figured out one problem. I was only using the class name instead of the fully-qualified class name (Blah instead of a.b.c.Blah) for the targetEntity in my ParentAdapter and ChildAdapter. Also, instead of using Blah for the targetEntity, the AbstractBlah was used. So now it appears something like the following:

Code:
@OneToMany(targetEntity = "a.b.c.AbstractBlah") @AssociationTable(table = @Table(name = "parentChildren"), joinColumns = {@JoinColumn(name = "parent_id")}, inverseJoinColumns = @JoinColumn(name = "child_id")) public Collection<Blah> getChildren() { ... }


The other item that I have now run across is that I would like to not include certain classes that are extended by a particular entity. For example, I have a class called LoggingSupport that handles some logging functionality for my program, and I would not like to have the particular Entity examine the properties in the LoggingSupport class. Is there a way to explicitly say "please ignore the LoggingSupport class"? I know that adding @Transient will ignore a particular function, but I would like to avoid having to put this information everywhere.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 19, 2005 7:10 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
The next EJB3 spec will address these annotations inheritance issues.

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

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.