Bugs item #663037, was opened at 2003-01-06 02:57
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=428708&aid=663037&group_id=40712
Category: None
Group: None
Status: Open
Resolution: None
Priority: 8
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Nobody/Anonymous (nobody)
Summary: Interface Inheritance not seen at Runtime
Initial Comment:
Hi!
Congratulations for Hibernate !
In our project, we are going to migrate from JDO to
Hibernate !
I encounter only one little pb with the use of Java
Interface in the mapping file, the hierachie of Interfaces
is ignored by hibernate.
Example:
Java Interfaces :
<<<<
package interfaces;
public interface Reference {
public abstract void setRef(String ref);
public abstract String getRef();
}
>>>>
<<<<
package interfaces;
public interface Referenceable {
public Reference getReference();
public void setReference(Reference reference);
}
>>>>
<<<<
package interfaces;
import java.util.Collection;
public interface Child extends Referenceable {
public Collection getParents();
public void setParents(Collection parents);
public Collection getAncestors();
public void setAncestors(Collection ancestors);
public boolean addParent(Parent parent);
public boolean removeParent(Parent parent);
public boolean isChildOf(Parent parent);
public boolean isDescendentOf(Parent ancestor);
}
>>>>
<<<<
package com.agrochannels.qxe;
import java.util.Collection;
public interface Parent extends Child {
public Collection getChildren();
public void setChildren(Collection children);
public Collection getDescendents();
public void setDescendents(Collection descendents);
public boolean addChild(Child child);
public boolean removeChild(Child child);
public boolean isParentOf(Child child);
public boolean isAncestorOf(Child child);
}
>>>>
And We have Implementations:
<<<<
package implementation;
public class ReferenceImpl implements Reference,
Serializable, UserType {
..
}
>>>>
<<<<
package implementation;
public abstract class ReferencedObjectImpl implements
Referenceable, Serializable {
..
}
>>>>
<<<<
package implementation;
public class ChildImpl extends ReferencedObjectImpl
implements Child {
..
}
>>>>
<<<
package implementation;
public class ParentImpl extends ChildImpl implements
Parent {
..
}
>>>
And with this hibernate mapping file :
<<<<
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 1.1//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-
1.1.dtd">
<hibernate-mapping>
<!-- interfaces.Referenceable root -->
<class name="interfaces.Referenceable"
table="Referenceable">
<id name="reference"
type="implementation.ReferenceImpl">
<generator
class="assigned"/>
</id>
<discriminator/>
<subclass
name="implementation.ReferencedObjectImpl">
</subclass>
<subclass
name="interfaces.Child">
<bag role="parents"
table="parents"
lazy="true"
cascade="all">
<key
column="child_ref"/>
<many-to-
many class="interfaces.Parent" column="parent_ref"/>
</bag>
<bag role="ancestors"
table="ancestors"
lazy="true"
cascade="all">
<key
column="child_ref"/>
<many-to-
many class="interfaces.Parent" column="parent_ref"/>
</bag>
<subclass
name="implementation.ChildImpl">
</subclass>
<subclass
name="interfaces.Parent">
<bag
role="children"
table="parents"
readonly="true"
lazy="true"
cascade="all">
<key column="parent_ref"/>
<many-to-many class="interfaces.Child"
column="child_ref"/>
</bag>
<bag
role="descendents"
table="ancestors"
readonly="true"
lazy="true"
cascade="all">
<key column="parent_ref"/>
<many-to-many class="interfaces.Child"
column="child_ref"/>
</bag>
<subclass
name="implementation.ParentImpl">
</subclass>
</subclass>
</subclass>
</class>
</hibernate-mapping>
>>>>
I can export the schema with
cirrus.hibernate.tools.SchemaExport but at Runtime
I get this exception :
[java] cirrus.hibernate.PropertyNotFoundException:
Could not find a getter
for reference in class interfaces.Child
[java] at
cirrus.hibernate.helpers.ReflectHelper.getGetter
(ReflectHelpe
r.java:198)
[java] at
cirrus.hibernate.helpers.ReflectHelper.setter
(ReflectHelper.j
ava:164)
[java] at
cirrus.hibernate.helpers.ReflectHelper.getSetter
(ReflectHelpe
r.java:145)
[java] at
cirrus.hibernate.persister.AbstractEntityPersister.<init>
(Abs
tractEntityPersister.java:487)
[java] at
cirrus.hibernate.persister.EntityPersister.<init>
(EntityPersi
ster.java:641)
[java] at
cirrus.hibernate.impl.SessionFactoryImpl.<init>
(SessionFactor
yImpl.java:192)
[java] at
cirrus.hibernate.impl.DatastoreImpl.buildSessionFactory
(Datas
toreImpl.java:403)
[java] at
cirrus.hibernate.impl.DatastoreImpl.buildSessionFactory
(Datas
toreImpl.java:392)
Or the getReference() method in Child is inherited from
Referenceable !
I have a workaround :
When I add explicitly the necessary methods in Child
and other Interfaces, it works.
I think that it seems only necessary to correct the
method cirrus.hibernate.helpers.ReflectHelper.getGetter()
to deal with interfaces and their inheritance.
I hope It was clear (I could have provided a simplier
example with 2 interfaces, my english is not very
good...).
Thanks,
Frank
----------------------------------------------------------------------
Comment By: Mark Woon (unkyaku)
Date: 2003-01-06 15:34
Message:
Logged In: YES
user_id=435832
Awesome. I've run into the same problem and didn't have
time to figure out what was wrong in Hibernate.
----------------------------------------------------------------------
Comment By: Gavin King (oneovthafew)
Date: 2003-01-06 15:21
Message:
Logged In: YES
user_id=384580
Yes, you are right! I didn't realise this problem existed ....
The trouble is that ReflectHelper only scans superclasses,
not superinterfaces for property declarations. This is
almost always okay, since concrete classes redefine the
property themselves and mapping interfaces is unusual
(though certainly not wrong). In this case where we have
interface _inheritance_, it breaks.
I will fix this ASAP, in both the 2.0 and 1.2 source trees.
(The fix should be there in about 12 hours or so.....)
Thanks!
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=428708&aid=663037&group_id=40712
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
hibernate-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/hibernate-devel