This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes An association from the table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "An association from the table "dependent" refers to an unmapped class: "Independent"" Watch "An association from the table "dependent" refers to an unmapped class: "Independent"" New topic
Author

An association from the table "dependent" refers to an unmapped class: "Independent"

Angel Mendoza
Greenhorn

Joined: Feb 02, 2010
Posts: 3
Hello,

I'm having problems when i try to tell hibernate my Class Rol(rolid, rolnombre) has multiple Menu(menuid, menuarchivo, menupresentacion). It's a many-to-many relationship and i use menuxrol table in order to handle the relation.
As i want it to be an unidirectional relation i only say java that the class Rol is the one that has a Set of menus even if i could also say that a Menu could has a Set of the roles it corresponds to.
But i get this error and i don't know what to do, I've been reading and in the configuration file i have both of this files mapped.
<mapping resource="modelo/Menu.hbm.xml"/>
<mapping resource="modelo/Rol.hbm.xml"/>

org.hibernate.MappingException: An association from the table menuxrol refers to an unmapped class: Menu
at org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:1252)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1170)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:324)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1286)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)

Rol.hbm.xml

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

<hibernate-mapping>
<class name="modelo.Rol" table="rol" catalog="gastos01">
<id name="id" type="string">
<column name="rolid" length="10" />
<generator class="assigned" />
</id>
<property name="nombre" type="string">
<column name="rolnombre" length="20" not-null="true" />
</property>
<set name="menus" inverse="true" table="menuxrol">
<key>
<column name="rolid" length="10" not-null="true" />
</key>
<many-to-many column="menuid" class="Menu"/>
</set>
</class>
</hibernate-mapping>

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

<hibernate-mapping>
<class name="modelo.Menu" table="menu" catalog="gastos01">
<id name="id" type="string">
<column name="menuid" length="10" />
<generator class="assigned" />
</id>
<property name="archivo" type="string">
<column name="menuarchivo" length="25" not-null="true" />
</property>
<property name="presentacion" type="string">
<column name="menupresentacion" length="50" not-null="true" />
</property>
</class>
</hibernate-mapping>
Angel Mendoza
Greenhorn

Joined: Feb 02, 2010
Posts: 3
Damn!!! Almost 2 days in this issue and it was a stupidity!

It seems hibernate and everything in life like things very well specified, and the problem i had was in this line:

<set name="menus" inverse="true" table="menuxrol">
<key>
<column name="rolid" length="10" not-null="true" />
</key>
<many-to-many column="menuid" class="modelo.Menu"/>
</set>

If you look to my first post i was not specifying the package containing my class Menu, so when i specified everything worked perfectly.

Looking forward to help some newbie like me with this reply.!
Andreas Erber
Greenhorn

Joined: Oct 03, 2009
Posts: 20
Hi Angel,

have you tried to specify the associated class appropriately? Try one of the following two options:

1) see the modified <many-to-many>-element


2) see the modified <hibernate-mapping> and the <class> element


CU
Froestel

Btw: Make heavy use of the BBCode buttons atop of the subject field. It's much easier to read your postings then, esp. the code snippets.
Angel Mendoza
Greenhorn

Joined: Feb 02, 2010
Posts: 3
Thanks Andreas,

That was the problem, hehe!
Andreas Erber
Greenhorn

Joined: Oct 03, 2009
Posts: 20
Hi Angel,

Angel Mendoza wrote:Thanks Andreas,

That was the problem, hehe!


Wow, what a coincidence, working right in parallel - sorry, man, I recognized afterwards that you already figured it out.

CU
Froestel
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: An association from the table "dependent" refers to an unmapped class: "Independent"
 
Similar Threads
Joining tables
Mapping Exception
Retereive data by ORDER BY
Hibernate problem: One-To-Many association
Association references unmapped class exception with hibernate