-->
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.  [ 5 posts ] 
Author Message
 Post subject: Association to subclass -> property-ref not found
PostPosted: Wed Mar 03, 2004 5:11 am 
Newbie

Joined: Tue Feb 17, 2004 2:51 pm
Posts: 10
Hello,

First of all, thanks for this truly impressive product!

Now, over to a problem which I tried to overcome most of yesterday..

I have a table-per-class hierarchy mapping with a superclass and a subclass.

In addition I have a third table/class which I want to associate to the subclass. It looks like this:

Code:
TABLE1 --+--> SuperClass (has property "assocKey")
         |
         +--> SubClass

TABLE2 -----> OtherClass
               <many-to-one>
                   class="SubClass"
                   property-ref="assocKey"


The reason I'm using property-ref is that assocKey is not the
primary key of SuperClass.

When loading the mapping into Hibern8 IDE I get the following
errormessage:

net.sf.hibernate.MappingException: property-ref not found: assocKey in class: SubClass

So, it almost looks like SubClass doesn't inherit the property assocKey
from SuperClass. I have also tried to add assocKey to SubClass (which doesn't make sense, and instead I got another errormessage).

The generated SubClass (from the hbm.xml file) do extend
SuperClass

More detailed mapping follows:

SuperClass and SubClass mapping:

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

<class name="SuperClass"
    table="TABLE1"
>
    <id
        name="id"
    </id>
   
    <discriminator column="DISCR_COL" type="java.lang.String"/>
       
    <property
        name="assocKey"
        column="ASSOCKEY"
        type="java.lang.String"
        length="19"
    />

    <!-- subclasses -->
   
    <subclass name="SubClass"
        discriminator-value="contractor">                 
    </subclass>
                   
</class>
</hibernate-mapping>

OTHERCLASS mapping:

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

<class  name="OtherClass"
    table="OTHERTABLE"
>
    <id (...)
     </id>
       
    <!-- associations -->
   
    <many-to-one
        name="subClass"
        class="SubClass"       
        property-ref="assocKey"
        unique="true"/>
</class>


Stack trace when loading the mapping:

[java] net.sf.hibernate.MappingException: property-ref not found: assocKey in class: SubClass [java] at net.sf.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:610)
[java] at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:732)
[java] at net.sf.hibern8ide.Hibern8IDE.initialize(Hibern8IDE.java:171)
[java] at net.sf.hibern8ide.Hibern8IDE.reconfig(Hibern8IDE.java:160)
[java] at net.sf.hibern8ide.Hibern8IDE$6.configurationChanged(Hibern8IDE.java:586)
[java] at net.sf.hibern8ide.ConfigurationUI$ApplyConfig.actionPerformed(ConfigurationUI.java:245)
[java] at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)
[java] at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)
[java] at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
[java] at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
[java] at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)
[java] at java.awt.Component.processMouseEvent(Component.java:5100)
[java] at java.awt.Component.processEvent(Component.java:4897)
[java] at java.awt.Container.processEvent(Container.java:1569)
[java] at java.awt.Component.dispatchEventImpl(Component.java:3615)
[java] at java.awt.Container.dispatchEventImpl(Container.java:1627)
[java] at java.awt.Component.dispatchEvent(Component.java:3477)
[java] at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483)
[java] at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)
[java] at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)
[java] at java.awt.Container.dispatchEventImpl(Container.java:1613)
[java] at java.awt.Window.dispatchEventImpl(Window.java:1606)
[java] at java.awt.Component.dispatchEvent(Component.java:3477)
[java] at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
[java] at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
[java] at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
[java] at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
[java] at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
[java] at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 03, 2004 5:16 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
The mapping makes no sense at all. Please look again at http://www.hibernate.org/hib_docs/reference/html/or-mapping.html#or-mapping-s1-9, the property-ref should be in a one-to-one element and the other side should be a "many-to-one".


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 03, 2004 6:49 am 
Newbie

Joined: Tue Feb 17, 2004 2:51 pm
Posts: 10
Thanks for your reply!

The strange thing is that when I have a <many-to-one> mapping in OtherClass (as it should be) then I get no errormessage when class="SuperClass" and the queries seems to be correctly generated.

But when class="SubClass" I get the property-ref not found error when Hibernate loads the metadata.

According to the documentation it should be possible to use property-ref in a <many-to-one>...

It could very well be that I'm doing some stupid mistake, but its really strange when everything works with an association to the superclass but not the subclass.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 07, 2005 11:57 am 
Beginner
Beginner

Joined: Wed Sep 17, 2003 10:25 am
Posts: 36
How can we do this on a one-to-many association where we need to indicate that the association (property-ref) points to a column other than the primary key of the original table?

In my experience, this is a common case in legacy databases.

Should a different mechanism be used?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 14, 2009 11:26 am 
Newbie

Joined: Tue Sep 16, 2008 11:10 am
Posts: 7
Has anybody found a solution (or bug) for this issue?


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