First, Hibernate Mailing List might be a better list to answer your questions. However, i'll try to answer as am also an Hibernate user. Le Mardi 20 Septembre 2005 06:30, Murray Collingwood a écrit : > 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.
You mean you are persisting the Struts forms in database? This is dangerous i think. I'll recommend using the delegate design pattern to prevent user access to some setters of the bean (eg. Hibernate requires you to have a setOwner on a bean to populate it from database but you don't want somebody to be allowed to change the owner by doing someAction.do?owner=SomeFakeOwner) So better have form do this: getXXX(){ return theBean.getXXX(); } and persist theBean :) This way you have better control on form setters > > 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? > As Hibernate documentation says, put it along the POJO. If Hibernate didn't find it, it's perhaps because of your compilation process. Some ide/automated tools like maven only compile classes in src/ directory to target/ directory, they do not copy ressources. Try to create a separate ressources directory which is copied in target directory as part of compilation process. For info, here we put our .hbm files in webapp/WEB-INF/classes/com/company/somePath because in compilation process, webapp/* is copied in final war :) With all this, we have our own session factory which is a singleton having this in constructor: Configuration configuration = new Configuration(); // ensure that the *.hbm.xml is located in bin/be/rmi/intranet/db // (where the class is) for (int i = 0; i < persistedClasses.length; i++) { configuration.addClass(persistedClasses[i]); } sessionFactory = configuration.configure().buildSessionFactory(); with private static Class[] persistedClasses = new Class[] { V4_news.class, Scpub.class, User.class, Function.class, FunctionBackup.class, Vacancy.class, TimeKeeper.class, Project.class }; > Kind regards > mc > > > > FOCUS Computing > Mob: 0415 24 26 24 > [EMAIL PROTECTED] > http://www.focus-computing.com.au > > > -- David Delbecq Royal Meteorological Institute of Belgium - Pingouins dans les champs, hiver méchant --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]