Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp
I am working on a new project and we want to use Hibernate for the Object relational mapping. I have downloaded and tried out some good Hibernate examples. The application is using Struts and Oracle 9i.
It appears that I can externalize the query strings into the hibernate mapping file, and then retrieve them by using the getNamedQuery call.
Is this a good way to do it, or should one use DAO's to hold the queries?
If DAO's are to be used, that will add another layer of classes to be coded. Right now I already have the beans that correspond to the tables, the action forms, the actions, and the hiberante mapping files for each table.
I would like to know if there is any advantage to using DAO's. If I use DAO's, how will the session factory object be availabe to them? Right now I retrieve it in the action form as follows:
sessionfactory =
(SessionFactory)servlet.getServletContext()
.getAttribute(HibernateStrutsPlugIn.KEY_NAME);
session = sessionfactory.openSession();
Thanks.
Hibernate version: 2.1.8
Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.sample.beans.Company" table="MGMT_COMPANIES">
<id name="id" type="long" column="MCP_ID_PK" >
<generator class="native">
<param name="sequence">COMPANYSEQ</param>
</generator>
</id>
<!-- A cat has to have a name, but it shouldn' be too long. -->
<property name="shrtName">
<column name="MCP_NUM_PK" />
</property>
<property name="address">
<column name="MCP_ADDRESS" />
</property>
<property name="city">
<column name="MCP_CITY" />
</property>
</class>
<query name="com.sample.whereMgmtCoEq">
<![CDATA[from com.sample.beans.Company
as company
where
company.shrtName = :shrtName]]>
</query>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
sessionfactory =
(SessionFactory)servlet.getServletContext()
.getAttribute(HibernateStrutsPlugIn.KEY_NAME);
session = sessionfactory.openSession();
Full stack trace of any exception that occurs:
Name and version of the database you are using:Oracle9i
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt: