I am working on a java JSP webapplication that uses the hibernate framework.
I am a total beginner with JSP/hibernate, and I can't seem to get hibernate to work. I have followed this tutorial: https://netbeans.org/kb/docs/web/hibernate-webapp.html It all worked. I used xampp with phpmyadmin, and I could execute HQL query's through the hibernate.cfg.xml file.
Then I was trying the same thing with the database I am using for the web application. Followed all steps and went through all the wizards. But I can't execute HQL query's.
the following error is given:
org.hibernate.MappingException: An association from the table campingsperfestival refers to an unmapped class: festivalOverview.Campings
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)
I followed the Hibernate Mapping Files and POJOs from Database wizard, and it generated a .java and .hbm.xml file for all tables in the database except for one table: the 'campingsperfestival' table. I've done the wizard again a few times and started it all over but it still doesn't generate the .java and .hbm.xml file for the 'campingsperfestival' table.
The 'campingsperfestival' table is a table with 2 id's that both have a foreign key. There are festivals and campings that both have ID's, the 'campingsperfestival' matches those 2 id's in one table.
Campings.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 20-apr-2013 12:04:37 by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
<class name="festivalOverview.Campings" table="campings" catalog="groep11_festivals">
<id name="campId" type="java.lang.Integer">
<column name="camp_id" />
<generator class="identity" />
</id>
<property name="campAdres" type="string">
<column name="camp_adres" not-null="true" />
</property>
<property name="campCap" type="int">
<column name="camp_cap" not-null="true" />
</property>
<set name="festivalses" inverse="true" table="campingsperfestival">
<key>
<column name="camp_id" not-null="true" />
</key>
<many-to-many entity-name="festivalOverview.Festivals">
<column name="fest_id" not-null="true" />
</many-to-many>
</set>
<set name="facpercamps" inverse="true">
<key>
<column name="camp_id" not-null="true" />
</key>
<one-to-many class="festivalOverview.Facpercamp" />
</set>
</class>
</hibernate-mapping>
Festivals.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 20-apr-2013 12:04:37 by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
<class name="festivalOverview.Festivals" table="festivals" catalog="groep11_festivals">
<id name="festId" type="java.lang.Integer">
<column name="fest_id" />
<generator class="identity" />
</id>
<property name="festNaam" type="string">
<column name="fest_naam" length="100" not-null="true" />
</property>
<property name="festLocatie" type="string">
<column name="fest_locatie" length="200" not-null="true" />
</property>
<property name="festDatum" type="date">
<column name="fest_datum" length="10" not-null="true" />
</property>
<property name="festDuur" type="byte">
<column name="fest_duur" not-null="true" />
</property>
<set name="ticketses" inverse="true">
<key>
<column name="fest_id" not-null="true" />
</key>
<one-to-many class="festivalOverview.Tickets" />
</set>
<set name="bandsperfestivals" inverse="true">
<key>
<column name="fest_id" not-null="true" />
</key>
<one-to-many class="festivalOverview.Bandsperfestival" />
</set>
<set name="campingses" inverse="false" table="campingsperfestival">
<key>
<column name="fest_id" not-null="true" />
</key>
<many-to-many entity-name="festivalOverview.Campings">
<column name="camp_id" not-null="true" />
</many-to-many>
</set>
<set name="tickettypesperfestivals" inverse="true">
<key>
<column name="fest_id" not-null="true" />
</key>
<one-to-many class="festivalOverview.Tickettypesperfestival" />
</set>
</class>
</hibernate-mapping>
I'm only a beginner with hibernate and really don't know how to solve this problem. Any help is greatly appreciated!