-->
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: how to use the any mapping?
PostPosted: Thu Aug 05, 2004 5:38 am 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
Hi

I'm using Hibernate 2.1.4 and MySql 4.0.20a.

I have a legacy DB with a table-per-concrete-class mapping, which I cannot change. So I tryed to get the mapping working by useing the <any> element. Unfortunately without sucess. I get an MappingException while reading the configuration.

I already read Chapter 5.2.5 of the reference manual and Chapter 6.4.2 of Hibernate in Action without finding the solution. Unfortunately it's not possible to search the Forum for something like "<any".

Any ideas what's wrong?
Ernst


The stack trace:
Code:
net.sf.hibernate.MappingException: broken column mapping for: rechtsgrund.CPerson of: hello.CPersonEigentum
   at net.sf.hibernate.persister.AbstractPropertyMapping.initPropertyPaths(AbstractPropertyMapping.java:88)
   at net.sf.hibernate.persister.AbstractPropertyMapping.initIdentifierPropertyPaths(AbstractPropertyMapping.java:123)
   at net.sf.hibernate.persister.AbstractPropertyMapping.initPropertyPaths(AbstractPropertyMapping.java:104)
   at net.sf.hibernate.persister.AbstractPropertyMapping.initPropertyPaths(AbstractPropertyMapping.java:80)
   at net.sf.hibernate.persister.AbstractEntityPersister.initPropertyPaths(AbstractEntityPersister.java:514)
   at net.sf.hibernate.persister.EntityPersister.postInstantiate(EntityPersister.java:110)
   at net.sf.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:156)
   at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:768)
   at hello.SessionFactoryManager.<init>(SessionFactoryManager.java:27)
   at hello.SessionFactoryManager.getInstance(SessionFactoryManager.java:36)
   at hello.HalfFkTest.testHalfFk(HalfFkTest.java:27)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:324)
   at junit.framework.TestCase.runTest(TestCase.java:154)
   at junit.framework.TestCase.runBare(TestCase.java:127)
   at junit.framework.TestResult$1.protect(TestResult.java:106)
   at junit.framework.TestResult.runProtected(TestResult.java:124)
   at junit.framework.TestResult.run(TestResult.java:109)
   at junit.framework.TestCase.run(TestCase.java:118)
   at junit.framework.TestSuite.runTest(TestSuite.java:208)
   at junit.framework.TestSuite.run(TestSuite.java:203)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)



This are the mapping documetns:
Rechtsgrund.hbm.xml
Code:
<hibernate-mapping>
   <class name="hello.Rechtsgrund" table="RECHTSGRUND">
      <id name="id">
         <generator class="increment"></generator>
      </id>
      <any name="CPerson" id-type="long" meta-type="string">
         <meta-value value="CPERSONEIGENTUM" class="hello.CPersonEigentum"/>
         <column name="FOREIGN_TABLE"/>
         <column name="FOREIGN_ID"/>
      </any>
      <property name="grund"></property>
   </class>
</hibernate-mapping>


CPersonEigentum.hbm.xml
Code:
<hibernate-mapping>
   <class name="hello.CPersonEigentum" table="CPERSONEIGENTUM">
      <id name="id">
         <generator class="increment"/>
      </id>
      <one-to-one name="rechtsgrund" property-ref="CPerson" cascade="all"/>
      <property name="nameA" column="NAME_A"/>
   </class>
</hibernate-mapping>


And this are the Java classes:
Rechtsgrund.java
Code:
public class Rechtsgrund {

    private Long myId;
    //private RechtsGrundHalter myRgHalter;
    private CPersonEigentum myCPerson;
    private String myGrund;

   
    public Long getId() {
        return myId;
    }
    public void setId(Long id) {
        myId = id;
    }
    public String getGrund() {
        return myGrund;
    }
    public void setGrund(String grund) {
        myGrund = grund;
    }
    public CPersonEigentum getCPerson() {
        return myCPerson;
    }
    public void setCPerson(CPersonEigentum person) {
        myCPerson = person;
    }
}


CPersonEigentum.java
Code:
public class CPersonEigentum {

    private String myNameA;
    private Long myId;
    private Rechtsgrund myRechtsgrund;
   
   
    public Long getId() {
        return myId;
    }
    public void setId(Long id) {
        myId = id;
    }
    public Rechtsgrund getRechtsgrund() {
        return myRechtsgrund;
    }
    public void setRechtsgrund(Rechtsgrund rechtsgrund) {
        myRechtsgrund = rechtsgrund;
    }
    public String getNameA() {
        return myNameA;
    }
    public void setNameA(String nameA) {
        myNameA = nameA;
    }
}


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 05, 2004 10:21 am 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
I seams that I should have read also Chapter 8.2 of the reference manual, telling me that with the <any> element only <many-to-any> is suported.

Sorry for posting this.
Ernst


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.