-->
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.  [ 3 posts ] 
Author Message
 Post subject: Help w/inner class
PostPosted: Fri Dec 04, 2009 2:34 pm 
Newbie

Joined: Thu Nov 26, 2009 1:55 pm
Posts: 3
Hi,

I've started using Hibernate a few days ago and i was trying to map a class which has an inner class. The java class is generated using jaxb and derives from IFC schema , so i think can't really avoid inner classes.

I have something like this:
Code:
public class A{

         public static class B{
                    //...
         }
}


Now, i know that one can map inner classes using the "foo$bar technique". So, i created a new hbm map file.

A.hbm.xml:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 18/Nov/2009 14:54:38 by Hibernate Tools 3.2.5.Beta -->
<hibernate-mapping>
    <class name="package.A" entity-name="A" table="A">
          <!--(properties...)-->
        <many-to-one name="B" class="package.A$B" column="B" fetch="join"/>   
    </class>
</hibernate-mapping>


A$B.hbm.xml:
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">
<!-- Generated 18/Nov/2009 14:54:38 by Hibernate Tools 3.2.5.Beta -->
<hibernate-mapping>
    <class name="package.A$B" entity-name="B" table="B">
   </class>   
</hibernate-mapping>


I'm getting the following exception:
Code:
java.lang.ExceptionInInitializerError
   at package.Main.<clinit>(Main.java:31)
Caused by: org.hibernate.MappingException: An association from the table A refers to an unmapped class: package.A$B


Does any of you have a clue on what might be the problem?
Even if you have an example using inner classes i'd appreciate pointing it to me, cause right know I'm not finding anything related to this matter. Well, actually any help at all is appreciated.

Thanks in advance.


Top
 Profile  
 
 Post subject: Re: Help w/inner class
PostPosted: Wed Dec 09, 2009 1:25 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
...I assume package is not really the name of the package ?

And you also are sure you actually added both of these mapping files to the configuration ?


Top
 Profile  
 
 Post subject: Re: Help w/inner class
PostPosted: Wed Dec 09, 2009 1:39 pm 
Newbie

Joined: Thu Nov 26, 2009 1:55 pm
Posts: 3
Yes, just changed the names of both classes and package for easier understanding.

My config looks like this:
Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
      <property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
        <property name="connection.url">jdbc:hsqldb:mem:testdb</property>
        <property name="connection.username">sa</property>
        <property name="connection.password"></property>

        <!-- JDBC connection pool (use the built-in) -->
        <property name="connection.pool_size">2</property>

        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.HSQLDialect</property>

        <!-- Echo all executed SQL to stdout
        <property name="show_sql">true</property>
        <property name="hbm2ddl.auto">create</property>-->
       
      <!-- Mapping files -->
       <mapping resource="A$B.hbm.xml"/>   
      <mapping resource="A.hbm.xml"/>

</session-factory>
</hibernate-configuration>


Thanks for your help!


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