Note that there are some explanatory texts on larger screens.

plurals
  1. POHibernate generated POJOs
    primarykey
    data
    text
    <p>I am fairly a newbie with hibernate but I have been using Netbeans and hibernate reverse engineering tool to generate POJOs from an existing schema. All the POJOs for each table are created just fine except for join tables which i believe it is supposed to be this way as I can see the associations are being created in the mapping files. But the problem comes when I attempt to execute HBL query I get an exception that one of my join tables is not mapped. I know there is a mapping entry in config file, the only thing I could think of is that my data model is incorrect. I have a fairly large ER model but the problem tables are</p> <p>I have User, Student, Major and StudentMajor tables. Below are my create statements</p> <pre><code>CREATE TABLE IF NOT EXISTS `Portfolio`.`User` ( `919Number` INT(11) NOT NULL , `loginId` VARCHAR(45) NOT NULL , `password` VARCHAR(8) NOT NULL , `userType` VARCHAR(10) NOT NULL , `lastName` VARCHAR(45) NULL DEFAULT NULL , `firstName` VARCHAR(45) NULL DEFAULT NULL , PRIMARY KEY (`919Number`) ); CREATE TABLE IF NOT EXISTS `Portfolio`.`Student` ( `919Number` INT(11) NOT NULL , `LEVL_CODE` VARCHAR(10) NOT NULL , PRIMARY KEY (`919Number`) , INDEX `919Number` (`919Number` ASC) , CONSTRAINT `919Number` FOREIGN KEY (`919Number` ) REFERENCES `Portfolio`.`User` (`919Number` ) ON DELETE NO ACTION ON UPDATE NO ACTION); CREATE TABLE IF NOT EXISTS `Portfolio`.`Major` ( `majorCode` VARCHAR(10) NOT NULL , `majorDescription` VARCHAR(45) NULL DEFAULT NULL , PRIMARY KEY (`majorCode`) ); CREATE TABLE IF NOT EXISTS `Portfolio`.`StudentMajor` ( `919Number` INT(11) NOT NULL , `majorCode` VARCHAR(10) NOT NULL , PRIMARY KEY (`919Number`, `majorCode`) , INDEX `studentmajor_919Number` (`919Number` ASC) , INDEX `studentmajor_majorCode` (`majorCode` ASC) , CONSTRAINT `studentmajor_919Number` FOREIGN KEY (`919Number` ) REFERENCES `Portfolio`.`Student` (`919Number` ) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `studentmajor_majorCode` FOREIGN KEY (`majorCode` ) REFERENCES `Portfolio`.`Major` (`majorCode` ) ON DELETE NO ACTION ON UPDATE NO ACTION); </code></pre> <p>Here is my hibernate config file</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"&gt; &lt;hibernate-configuration&gt; &lt;session-factory&gt; &lt;property name="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/property&gt; &lt;property name="hibernate.connection.driver_class"&gt;com.mysql.jdbc.Driver&lt;/property&gt; &lt;property name="hibernate.connection.url"&gt;jdbc:mysql://localhost:3306/portfolio&lt;/property&gt; &lt;property name="hibernate.connection.username"&gt;root&lt;/property&gt; &lt;property name="hibernate.connection.password"&gt;admin&lt;/property&gt; &lt;property name="hibernate.show_sql"&gt;true&lt;/property&gt; &lt;property name="hibernate.current_session_context_class"&gt;jta&lt;/property&gt; &lt;property name="hibernate.query.factory_class"&gt;org.hibernate.hql.ast.ASTQueryTranslatorFactory&lt;/property&gt; &lt;mapping resource="com/portfolio/hibernate/mappings/User.hbm.xml"/&gt; &lt;mapping resource="com/portfolio/hibernate/mappings/Student.hbm.xml"/&gt; &lt;mapping resource="com/portfolio/hibernate/mappings/Major.hbm.xml"/&gt; &lt;/session-factory&gt; &lt;/hibernate-configuration&gt; </code></pre> <p>and I am using Netbeans hibernate POJO genereation tool. But when I run the queries I get the below exception:</p> <blockquote> <p>org.hibernate.MappingException: An association from the table studentmajor refers to an unmapped class: com.portfolio.hibernate.mappings.Student 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)</p> </blockquote> <p>Is there a possibility that this error is caused by the way I have modeled my tables? Any help will be appreciated.</p> <p>As suggested I am including contents of the hbm.xml files for Student and Major.</p> <p>Student:::</p> <pre><code>&lt;hibernate-mapping&gt; &lt;class name="com.jopos.Student" table="student" catalog="portfolio"&gt; &lt;id name="nineOneNumber" type="int"&gt; &lt;column name="nineOneNumber" /&gt; &lt;generator class="assigned" /&gt; &lt;/id&gt; &lt;many-to-one name="user" class="com.jopos.User" update="false" insert="false" fetch="select"&gt; &lt;column name="nineOneNumber" not-null="true" unique="true" /&gt; &lt;/many-to-one&gt; &lt;property name="levlCode" type="string"&gt; &lt;column name="LEVL_CODE" length="10" not-null="true" /&gt; &lt;/property&gt; &lt;set name="faculties" inverse="false" table="advises"&gt; &lt;key&gt; &lt;column name="studentnineOneNumber" not-null="true" /&gt; &lt;/key&gt; &lt;many-to-many entity-name="com.jopos.Faculty"&gt; &lt;column name="facultynineOneNumber" not-null="true" /&gt; &lt;/many-to-many&gt; &lt;/set&gt; &lt;set name="majors" inverse="false" table="studentmajor"&gt; &lt;key&gt; &lt;column name="nineOneNumber" not-null="true" /&gt; &lt;/key&gt; &lt;many-to-many entity-name="com.jopos.Major"&gt; &lt;column name="majorCode" length="10" not-null="true" /&gt; &lt;/many-to-many&gt; &lt;/set&gt; &lt;set name="enrolls" inverse="true"&gt; &lt;key&gt; &lt;column name="nineOneNumber" not-null="true" /&gt; &lt;/key&gt; &lt;one-to-many class="com.jopos.Enroll" /&gt; &lt;/set&gt; &lt;/class&gt; &lt;/hibernate-mapping&gt; </code></pre> <p>Major:::</p> <pre><code>&lt;hibernate-mapping&gt; &lt;class name="com.jopos.Major" table="major" catalog="portfolio"&gt; &lt;id name="majorCode" type="string"&gt; &lt;column name="majorCode" length="10" /&gt; &lt;generator class="assigned" /&gt; &lt;/id&gt; &lt;property name="majorDescription" type="string"&gt; &lt;column name="majorDescription" length="45" /&gt; &lt;/property&gt; &lt;set name="students" inverse="true" table="studentmajor"&gt; &lt;key&gt; &lt;column name="majorCode" length="10" not-null="true" /&gt; &lt;/key&gt; &lt;many-to-many entity-name="com.jopos.Student"&gt; &lt;column name="nineOneNumber" not-null="true" /&gt; &lt;/many-to-many&gt; &lt;/set&gt; &lt;/class&gt; &lt;/hibernate-mapping&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload