Hi all
Hibernate is an excellent tool! I managed to get it running quite quickly,
only a few
small issues to resolve, fortunately the error messages were fairly clear.
I've implemented Hibernate into the beginning of a new Struts app, however my
code
isn't looking like the examples and I'm wondering if I'm putting files in the
wrong places.
Here is the structure I have:
Note, the term "Menu" here refers to a restaurant menu item.
Form bean "MenuForm" is stored in com.path.controller.form
Action class is in com.path.controller.action
In this app my form beans reflect closely the database so I am using the same
form
bean classes for the model.
I created "Menu.hbm.xml" and tried placing it in com.path.controller.form as
the
Hibernate documentation said to place these 'hbm' files with the pojos. When I
tried to
start the app Hibernate complained that it couldn't find the Menu.hbm.xml file.
So I
moved the file around a bit, finally placing it in the root of the Source
directory, eg
"src/Menu.hbm.xml" with "src/com/path/controller/form/MenuForm.java". The
contents
of my Menu.hbm.xml is as follows:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.path.controller.form.MenuForm" table="Menu">
<id name="mid">
<generator class="native"/>
</id>
<property name="title"/>
<property name="description"/>
<property name="price" type="float"/>
<property name="rating" type="int"/>
<property name="dateFrom" type="date"/>
<property name="dateTo" type="date"/>
<property name="imageid" type="int"/>
</class>
</hibernate-mapping>
My hibernate.cfg.xml is:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property
name="connection.datasource">java:comp/env/jdbc/dbname</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">create</property>
<!-- Mapping files -->
<mapping resource="Menu.hbm.xml"/>
</session-factory>
</hibernate-configuration>
THE QUESTION IS: My hbm file is not stored next to the pojo and has to
reference it
using the full path. Is this normal? Is there a better way of doing this?
Kind regards
mc
FOCUS Computing
Mob: 0415 24 26 24
[EMAIL PROTECTED]
http://www.focus-computing.com.au
--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.344 / Virus Database: 267.10.25/102 - Release Date: 14/09/2005
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]