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.