-->
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.  [ 4 posts ] 
Author Message
 Post subject: how do i map cyclic class references
PostPosted: Mon Nov 29, 2004 11:28 am 
Newbie

Joined: Mon Nov 17, 2003 10:53 am
Posts: 15
Hibernate version:
2.1.16
Mapping documents:
Code:
<hibernate-mapping auto-import="false">
  <class name="foo.Value"
         table="VALUE" schema="TEST"
         dynamic-update="false" 
         dynamic-insert="false" >

  <id name="id" column="id" type="string" >
     <generator class="uuid.hex"/>
  </id>

  <!-- NONE OF THESE WORKS.
  <property name="parent"
      type="foo.Value" column="PARENT_ID"/>
  <many-to-one name="parent"
      type="foo.Value" column="PARENT_ID"/>
  <one-to-one name="parent"
      type="foo.Value" column="PARENT_ID"/>
  -->

  </class>

</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
none

Full stack trace of any exception that occurs:
[java] net.sf.hibernate.MappingException: Error reading resource: foo/Value.hbm.xml
[java] at net.sf.hibernate.cfg.Configuration.addClass(Configuration.java:357)
[java] at foo.TestPersistence.testValue(TestPersistence.java:48)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[java] at java.lang.reflect.Method.invoke(Method.java:324)
[java] at junit.framework.TestCase.runTest(TestCase.java:154)
[java] at junit.framework.TestCase.runBare(TestCase.java:127)
[java] at junit.framework.TestResult$1.protect(TestResult.java:106)
[java] at junit.framework.TestResult.runProtected(TestResult.java:124)
[java] .
[java] Time: 0,546

[java] OK (1 test)
[java] at junit.framework.TestResult.run(TestResult.java:109)
[java] at junit.framework.TestCase.run(TestCase.java:118)
[java] at junit.framework.TestSuite.runTest(TestSuite.java:208)
[java] at junit.framework.TestSuite.run(TestSuite.java:203)
[java] at junit.textui.TestRunner.doRun(TestRunner.java:116)
[java] at junit.textui.TestRunner.doRun(TestRunner.java:109)
[java] at junit.textui.TestRunner.run(TestRunner.java:72)
[java] at de.payon.entities.test.TestPersistence.main(TestPersistence.java:111)
[java] Caused by: net.sf.hibernate.MappingException: Could not interpret type: foo.Value
[java] at net.sf.hibernate.cfg.Binder.getTypeFromXML(Binder.java:933)
[java] at net.sf.hibernate.cfg.Binder.bindSimpleValue(Binder.java:434)
[java] at net.sf.hibernate.cfg.Binder.propertiesFromXML(Binder.java:1046)
[java] at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:361)
[java] at net.sf.hibernate.cfg.Binder.bindRoot(Binder.java:1253)
[java] at net.sf.hibernate.cfg.Configuration.add(Configuration.java:252)
[java] at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:288)
[java] at net.sf.hibernate.cfg.Configuration.addClass(Configuration.java:354)
[java] ... 17 more


Name and version of the database you are using:
postgres 7.4

The generated SQL (show_sql=true):
none

Debug level Hibernate log excerpt:
none

given the following class. how do i define
a mapping file that allows for cyclic
references?

Code:
package foo;
public class Value
{
    private String id_;
    private Value parent_;
   
    public String getId()
    {
        return id_;
    }
   
    public Value setId(String _value)
    {
        id_ = _value;
        return this;
    }

    public Value getParent()
    {
        return parent_;
    }

    public Value setParent(Value _value)
    {
        parent_ = _value;
        return this;
    }
}



when using the following code i get the
exception described above. does anybody
know how to do that correct?
Code:
public void testValue()
{
  try
  {
    Configuration cfg = new Configuration();

    InputStream is =
    Util.getResource("foo/Value.hbm.xml");
    cfg.addInputStream(is);
  }
  catch (Exception ex)
  {
    LOGGER.log(Level.SEVERE, "");
    ex.printStackTrace();
  }
}


thanks

ciao robertj


Top
 Profile  
 
 Post subject: Re: how do i map cyclic class references
PostPosted: Mon Nov 29, 2004 11:45 am 
Beginner
Beginner

Joined: Tue Oct 26, 2004 12:45 pm
Posts: 43
Location: Israel
robertj wrote:
<many-to-one name="parent"
type="foo.Value" column="PARENT_ID"/>


you should use:

<many-to-one name="parent"
class="foo.Value" column="PARENT_ID"/>

hope it helps.
Jus.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 29, 2004 11:59 am 
Newbie

Joined: Mon Nov 17, 2003 10:53 am
Posts: 15
hi issahar,

that was almost to easy.

i dont know how many time i have
read the docs for many-to-one but
i never cared about type vs class.

thank you very, very much!

ciao robertj
ps:damn cutting and pasting.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 29, 2004 12:04 pm 
Beginner
Beginner

Joined: Tue Oct 26, 2004 12:45 pm
Posts: 43
Location: Israel
robertj wrote:
ps:damn cutting and pasting.


Hi.
I use xDoclets, so:
1) if the ant task doesn't run, it means i have a problem with the mapping.
2) I don't have to look at the non-readable hbm's, and i have all the code at one place.

ps:
a friend of mine had a signature:
"God gave us copy/paste so we can destroy the world" :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.