-->
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.  [ 6 posts ] 
Author Message
 Post subject: one-to-one mapping and joined subclasses
PostPosted: Tue Apr 27, 2004 6:11 am 
Beginner
Beginner

Joined: Mon Feb 23, 2004 1:17 pm
Posts: 28
I've run into problems with my mappings and a mapping from one class to another class (which is mapped using a joined-subclass).

Mapping for class A:
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="ClassA"
        dynamic-update="false"
        dynamic-insert="false"
        mutable="true"
    >

        <id name="id" column="ClassAId" type="java.lang.String">
            <generator class="uuid.hex">
            </generator>
        </id>

        <version name="hbmVersion" type="long" column="hbmVersion"            access="field" />

        <one-to-one
            access="field"
            cascade="all"
            class="ClassB"
            name="classB"
            property-ref="classA"
         />
    </class>
</hibernate-mapping>



Mapping for ClassB
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>
    <joined-subclass
        name="ClassB"
        extends="ParentOfB"
        dynamic-update="false"
        dynamic-insert="false"
    >
        <key column="ParentOfBId" />
       
        <many-to-one
            class="ClassA"
            unique="true"
            access="property"
            cascade="all"
            property-ref="classB"
            name="ClassA"
         />
    </joined-subclass>
</hibernate-mapping>


The mappingsfile compiles until it reaches the processing of one-to-one relations:
Code:
12:00:51,390 INFO  [Configuration] processing one-to-one association property references
12:00:51,390 INFO  [Configuration] processing foreign key constraints


The error is:
Code:
Caused by: net.sf.hibernate.MappingException: property mapping has wrong number of columns: ClassB.classA type: ClassA
   at net.sf.hibernate.mapping.PersistentClass.validate(PersistentClass.java:269)
   at net.sf.hibernate.mapping.Subclass.validate(Subclass.java:141)
   at net.sf.hibernate.cfg.Configuration.validate(Configuration.java:576)
   at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:733)


Any ideas would be welcome.
-------------------
Hibernate: 2.1.2
Java: 1.4.2_03


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 27, 2004 6:13 am 
Beginner
Beginner

Joined: Mon Feb 23, 2004 1:17 pm
Posts: 28
One small error creeped into the mappingsfile above:

Code:
        <many-to-one
            class="ClassA"
            unique="true"
            access="property"
            cascade="all"
            property-ref="classB"
            name="ClassA"
         />


should read:

Code:
        <many-to-one
            class="ClassA"
            unique="true"
            access="property"
            cascade="all"
            property-ref="classB"
            name="classA"
         />


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 27, 2004 8:27 am 
Beginner
Beginner

Joined: Mon Feb 23, 2004 1:17 pm
Posts: 28
I've written a workaround by making these a property in ClassB, a one-to-one in ClassA and manually saving the relation each time. This is far from ideal.

Any other suggestions are still very welcome...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 28, 2004 11:57 am 
Beginner
Beginner

Joined: Mon Feb 23, 2004 1:17 pm
Posts: 28
Just tried with Hibernate 2.1.3 and still seeing this.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 30, 2004 12:45 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
PArentOfB has a composite ID ?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 03, 2004 6:20 am 
Beginner
Beginner

Joined: Mon Feb 23, 2004 1:17 pm
Posts: 28
It turned out that I still had a foreign-key added to the hbm.xml file. Removing this fixed the problem.


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