Hibernate exception

Posted by Mark on Stack Overflow See other posts from Stack Overflow or by Mark
Published on 2010-05-02T18:18:54Z Indexed on 2010/05/02 18:28 UTC
Read the original article Hit count: 501

Filed under:
|
|
|

Hi all, im new to hibernate! i have followed the netbeans tutorial on creating a hibernate enabled application. after sucessfully creating a database in mysql workbench i reversed engineered the pojos etc and then tried to run a simple query(from Course) and got the following

org.hibernate.MappingException: An association from the table coursemodule refers to an unmapped class: DAL.Module
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)

heres the generated class for Course

package DAL;
// Generated 02-May-2010 16:41:16 by Hibernate Tools 3.2.1.GA


import java.util.HashSet;
import java.util.Set;

/**
 * Course generated by hbm2java
 */
public class Course  implements java.io.Serializable {


 private int id;
 private String name;
 private Set<Module> modules = new HashSet<Module>(0);

public Course() {
}


public Course(int id, String name) {
    this.id = id;
    this.name = name;
}
public Course(int id, String name, Set<Module> modules) {
   this.id = id;
   this.name = name;
   this.modules = modules;
}

public int getId() {
    return this.id;
}

public void setId(int id) {
    this.id = id;
}
public String getName() {
    return this.name;
}

public void setName(String name) {
    this.name = name;
}
public Set<Module> getModules() {
    return this.modules;
}

public void setModules(Set<Module> modules) {
    this.modules = modules;
}
}

and its config file course.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"> <!-- Generated 02-May-2010 16:41:16 by Hibernate Tools 3.2.1.GA --> <hibernate-mapping>
    <class name="DAL.Course" table="course" catalog="walkthrough">
        <id name="id" type="int">
            <column name="id" />
            <generator class="assigned" />
        </id>
        <property name="name" type="string">
            <column name="name" not-null="true" />
        </property>
        <set name="modules" inverse="false" table="coursemodule">
            <key>
                <column name="courseId" not-null="true" unique="true" />
            </key>
            <many-to-many entity-name="DAL.Module">
                <column name="moduleId" not-null="true" unique="true" />
            </many-to-many>
        </set>
    </class> </hibernate-mapping>

hibernate.reveng.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd">
<hibernate-reverse-engineering>
  <schema-selection match-catalog="Walkthrough"/>
  <table-filter match-name="walkthrough"/>
  <table-filter match-name="course"/>
  <table-filter match-name="module"/>
  <table-filter match-name="studentmodule"/>
  <table-filter match-name="attendee"/>
  <table-filter match-name="student"/>
  <table-filter match-name="coursemodule"/>
  <table-filter match-name="session"/>
  <table-filter match-name="test"/>
</hibernate-reverse-engineering>

hibernate.cfg.xml

<?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/Walkthrough</property>
    <property name="hibernate.connection.username">root</property>
    <property name="hibernate.connection.password">password</property>
    <property name="hibernate.show_sql">true</property>
    <property name="hibernate.current_session_context_class">thread</property>
    <mapping resource="DAL/Student.hbm.xml"/>
    <mapping resource="DAL/Walkthrough.hbm.xml"/>
    <mapping resource="DAL/Test.hbm.xml"/>
    <mapping resource="DAL/Module.hbm.xml"/>
    <mapping resource="DAL/Session.hbm.xml"/>
    <mapping resource="DAL/Course.hbm.xml"/>
  </session-factory>
</hibernate-configuration>

any ideas on why im getting this exception? ps. test is just a table with an id in it and is not related to anything. running "from Test" works

© Stack Overflow or respective owner

Related posts about java

Related posts about netbeans