Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Hibernate Netbeans
PostPosted: Thu Jan 27, 2011 3:42 am 
Newbie

Joined: Wed Jan 26, 2011 3:51 pm
Posts: 1
Hi I wanted to use Netbeans generation of hibernate POJOs and mapping xmls but it is evidently malfunctioning.

I have a DB with tables A and B with a many to many relation(which is the relation thats doesnt work with Netbeans generation).

Can you see any obvious errors in the generations?


Here's the hibernate.cfg
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
  <session-factory>
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/mydb</property>
    <property name="hibernate.connection.username">root</property>
    <mapping resource="model/A.hbm.xml"/>
    <mapping resource="model/B.hbm.xml"/>
  </session-factory>
</hibernate-configuration>


and the 2 tables xmls
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 2011-jan-26 20:54:06 by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
    <class name="model.A" table="a" catalog="mydb">
        <id name="ida" type="int">
            <column name="ida" />
            <generator class="assigned" />
        </id>
        <set name="bs" inverse="false" table="a_has_b">
            <key>
                <column name="a_ida" not-null="true" />
            </key>
            <many-to-many entity-name="model.B">
                <column name="b_idb" not-null="true" />
            </many-to-many>
        </set>
    </class>
</hibernate-mapping>

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 2011-jan-26 20:54:06 by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
    <class name="model.B" table="b" catalog="mydb">
        <id name="idb" type="int">
            <column name="idb" />
            <generator class="assigned" />
        </id>
        <set name="as" inverse="false" table="a_has_b">
            <key>
                <column name="b_idb" not-null="true" />
            </key>
            <many-to-many entity-name="model.A">
                <column name="a_ida" not-null="true" />
            </many-to-many>
        </set>
    </class>
</hibernate-mapping>


So when I try Running a HQL(from A) on it it says:


Code:
org.hibernate.MappingException: An association from the table a_has_b refers to an unmapped class: model.B
   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)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

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.