Hello all, How can I map the mapping hibernate files (*.hbm.xml) with the generated classes with my current project structure?
My project uses only ony *.hmb.xml file with many class elements.
The file paths of the files are explained below:
Mapping xml file(*.hbm.xml): [PROJECT_PATH]/src/META-INF
Generated classes: [PROJECT_PATH]/src/essex/cc403
Hibernate version:
hibernate-2.1.8
Mapping documents:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="essex.cc403.hbeans.User" table="USER">
<meta attribute="class-description">
Represents a user in the database.
@author Konstantinos Karadamoglou
</meta>
<id name="id" type="int" column="USER_ID">
<meta attribute="scope-set">protected</meta>
<generator class="native"/>
</id>
<property name="password" type="string" not-null="true"/>
<property name="firstName" type="string" not-null="true"/>
<property name="lastName" type="string" not-null="true"/>
<property name="addLine1" type="string" not-null="true"/>
<property name="addLine2" type="string" not-null="false"/>
<property name="city" type="string" not-null="true"/>
<property name="county" type="string" not-null="true"/>
<many-to-one name="rank" class="essex.cc403.hbeans.Rank" column="RANK_ID"/>
</class>
<class name="essex.cc403.hbeans.Rank" table="RANK">
<meta attribute="class-description">
Represents a rank in the database.
@author Konstantinos Karadamoglou
</meta>
<id name="rankID" type="int" column="RANK_ID">
<meta attribute="scope-set">protected</meta>
<generator class="native"/>
</id>
<property name="name" type="string">
<meta attribute="use-in-tostring">true</meta>
<column name="NAME" not-null="true" unique="true" index="RANK_NAME"/>
</property>
<property name="canBook" type="boolean" not-null="true"/>
<property name="canDeleteAccount" type="boolean" not-null="true"/>
<property name="canViewBookings" type="boolean" not-null="true"/>
<property name="canEditBookings" type="boolean" not-null="true"/>
<property name="canCancelBookings" type="boolean" not-null="true"/>
<set name="Users" cascade="all" inverse="true" lazy="true">
<key column="RANK_ID"/>
<one-to-many class="essex.cc403.hbeans.User"/>
</set>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
Session session = sessionFactory.openSession();
Transaction tx = null;
try {
// Create some data and persist it
tx = session.beginTransaction();
Rank rank = new Rank(true, false, true, false, true, null);
session.save(rank);
User user = new User("123", "James", "Brown", "St. Paul 21",
"Colchester", "United Kingdom");
session.save(user);
// We're done; make our changes permanent
tx.commit();
} catch (Exception e) {
if (tx != null) {
// Something went wrong; discard all partial changes
tx.rollback();
}
throw e;
} finally {
// No matter what, close the session
session.close();
}
Full stack trace of any exception that occurs:Code:
log4j:WARN No appenders could be found for logger (net.sf.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
net.sf.hibernate.MappingException: Resource: essex/cc403/hbeans/User.hbm.xml not found
at net.sf.hibernate.cfg.Configuration.addClass(Configuration.java:352)
at essex.cc403.Main.main(Main.java:43)
Name and version of the database you are using:
hsqldb-1.7.3.3
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt: