-->
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.  [ 2 posts ] 
Author Message
 Post subject: Polymorphic Mapping with Interface -> PropertyNotFoundExc
PostPosted: Sun May 28, 2006 8:38 pm 
Newbie

Joined: Sun May 28, 2006 7:47 pm
Posts: 1
I am getting an error when building the session factory caused by the mapping document below. I am attempting to map a table per concrete class using union-subclass. The parent class is an interface and the subclasses implement that interface. They also extend another abstract class, so I cannot change the interface to an abstract class. The interface I reference as a field from another mapped class, so polymorphism is important.

The error is hibernate trying to find the id field on the interface. It looks for a superclass for the interface which returns null and throws the exception. It doesn't seem to realize this is an interface. I included the abstract="true" attribute but that doesn't make a difference.

I also tried implementing this as a table per class hiearchy using <subclass> and got the same error. From searching the forums, reference docs and Hibernate in Action, it would seem that one of these (or both) approaches should work, but I am not having any luck. I also can't find a complete working example anywhere that shows this type of inheritance mapping. The examples always seem to use concrete classes as the parent class. I've seen several similar posts that recommend using one of the approaches I have tried, but no reference to anyone getting this exception.

I've combed the forums, run through in the debugger, tried many different approaches without luck. I even tried implementing using <any> and it seemed to work in unit tests until integrated into my application then I ran into problems and I never liked that approach and see that it is not recommended.

Version Info: Hibernate Version 3.1 / Java JDK 1.5.0_06 / Oracle 10g

Mapping Doc:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="controlDomain" default-access="field" default-cascade="lock">
   <class name="AnalysisResult" abstract="true">
      <id name="id" column="ANALYSIS_ID" type="long">
            <generator class="hibernateUtil.GeneratedIdentifierGenerator">
            <param name="delegate">sequence</param>
            <param name="sequence">ANALYSIS_ID_SEQ</param>
            </generator>
      </id>

      <union-subclass name="AAnalysis" extends="AnalysisResult" table="A_ANALYSIS">
         <many-to-one name="source" class="Source" column="SOURCE_ID"/>
      ...   
      </union-subclass>
      
      <union-subclass name="BAnalysis" extends="AnalysisResult" table="B_ANALYSIS">
             <many-to-one name="analysisType" class="AnalysisType" column="ANALYSIS_TYPE_ID"/>
         <property name="analysisDateTime" column="ANALYSIS_DATE_TIME" type="timestamp"/>   
          ...
      </union-subclass>      
   </class>
</hibernate-mapping>


The Exception:
Code:
org.hibernate.PropertyNotFoundException: field not found: id
   at org.hibernate.property.DirectPropertyAccessor.getField(DirectPropertyAccessor.java:97)
   at org.hibernate.property.DirectPropertyAccessor.getField(DirectPropertyAccessor.java:104)
   at org.hibernate.property.DirectPropertyAccessor.getGetter(DirectPropertyAccessor.java:112)
   at org.hibernate.tuple.PropertyFactory.getGetter(PropertyFactory.java:166)
   at org.hibernate.tuple.PropertyFactory.buildIdentifierProperty(PropertyFactory.java:44)
   at org.hibernate.tuple.EntityMetamodel.<init>(EntityMetamodel.java:115)
   at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:412)
   at org.hibernate.persister.entity.UnionSubclassEntityPersister.<init>(UnionSubclassEntityPersister.java:63)
   at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:61)
   at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:215)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1154)


Debug level logging: no related log messages with debug turned up.

Related Code:
Code:
public interface AnalysisResult {
   public int getExceptionCount();
   public Long getId();
   public Set<ExceptionItem> getExceptions();
   ...
}

public class AAnalysis extends AbstractGenericEntity<AAnalysis, Long> implements AnalysisResult {
...
}

public class BAnalysis extends AbstractGenericEntity<BAnalysis, Long> implements AnalysisResult {
...
}

public abstract class AbstractGenericEntity<E extends AbstractGenericEntity, K extends Serializable> {
   private K id;
...
}




Let me know if any other information is needed. Would appreciate some assistance.

Regards,

Ken


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 29, 2006 6:02 am 
Regular
Regular

Joined: Wed Mar 08, 2006 2:07 am
Posts: 50
Location: Bangalore
I guess because u have specified 'id' as of type 'K' in abstract parent
class but in its xml mapping file you are just mapping it to a column
directly.
what I would say is that you create a composite key and make it of
type 'AbstractGenericEntityKey' and specify get/set methods for that Key
class.
Also make the key class to extend the interface. Then use the Key class
instead of interface (if your business logic allows :)

_________________
Prashant Jain

... right now I am in need of some credits !


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.