Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hi,
I am getting MappingException for Duplicate named query . I have "named queries" only in Employee and Location mapping files. And all "named query" names are different. Both mapping files and exception is listed below.
Please advise.
Thanks
JP
Hibernate version: 3.0
Mapping documents:
=============== Location.hbm.xml ====================
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping
>
<class
name="Location"
table="location"
lazy="false"
>
<cache usage="read-write" />
<id
name="OID"
column="oid"
type="java.lang.Long"
>
<generator class="sequence">
<param name="sequence">autotest_oid_seq</param>
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-Location.xml
containing the additional parameters and place it in your merge dir.
-->
</generator>
</id>
<property
name="site"
type="java.lang.String"
column="site"
not-null="false"
/>
<property
name="mailStop"
type="java.lang.String"
column="mailstop"
not-null="false"
/>
<property
name="building"
type="java.lang.String"
column="building"
not-null="true"
/>
<property
name="roomNumber"
type="java.lang.String"
column="room_num"
/>
<property
name="description"
type="java.lang.String"
column="description"
not-null="false"
/>
<property
name="active"
type="boolean"
column="active"
not-null="false"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Location.xml
containing the additional properties and place it in your merge dir.
-->
</class>
<query name="fetchAllLocations"><![CDATA[
from Location obj order by obj.building, obj.roomNumber
]]></query>
</hibernate-mapping>
===============================================
=============== Employee.hbm.xml ===================
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping
>
<class
name="Employee"
table="employee"
lazy="false"
>
<cache usage="read-write" />
<id
name="email"
column="email_address"
type="java.lang.String"
>
<generator class="assigned">
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-Employee.xml
containing the additional parameters and place it in your merge dir.
-->
</generator>
</id>
<many-to-one
name="homePage"
class="Servlet"
cascade="none"
outer-join="auto"
column="servletoid"
/>
<property
name="active"
type="boolean"
column="active"
/>
<property
name="firstName"
type="java.lang.String"
column="first_name"
not-null="true"
/>
<property
name="lastName"
type="java.lang.String"
column="last_name"
not-null="true"
/>
<property
name="cellPhone"
type="java.lang.String"
column="cell_phone_no"
/>
<property
name="pager"
type="java.lang.String"
column="pager_no"
/>
<set
name="groups"
table="empgroup"
lazy="false"
cascade="none"
sort="unsorted"
>
<cache
usage="read-write"
/>
<key
column="employee"
>
</key>
<many-to-many
class="Group"
column="group_name"
outer-join="true"
/>
</set>
<set
name="roles"
table="emprole"
lazy="false"
cascade="none"
sort="unsorted"
>
<cache
usage="read-write"
/>
<key
column="employee"
>
</key>
<many-to-many
class="Role"
column="roleoid"
outer-join="auto"
/>
</set>
<property
name="password"
type="java.lang.String"
column="password"
not-null="true"
/>
<many-to-one
name="location"
class="Location"
cascade="none"
outer-join="auto"
column="locationoid"
not-null="true"
/>
<property
name="expirationDate"
type="java.util.Date"
column="expiration_date"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Employee.xml
containing the additional properties and place it in your merge dir.
-->
</class>
<query name="fetchEmployees_active"><![CDATA[
from Employee obj where obj.active=1 order by obj.lastName, obj.firstName
]]></query>
<query name="fetchEmployees_all"><![CDATA[
from Employee obj order by obj.lastName, obj.firstName
]]></query>
</hibernate-mapping>
===============================================
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
(cfg.Configuration 362 ) Could not compile the mapping document
org.hibernate.MappingException: Duplicate query named: fetchAllLocations
at org.hibernate.cfg.Mappings.checkQueryExist(Mappings.java:220)
at org.hibernate.cfg.Mappings.addQuery(Mappings.java:209)
at org.hibernate.cfg.HbmBinder.bindNamedQuery(HbmBinder.java:2126)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:178)
at org.hibernate.cfg.Configuration.add(Configuration.java:359)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:396)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:445)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1312)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1284)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1266)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1233)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1161)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1147)
at HibernateUtil.<clinit>(HibernateUtil.java:47)
at HibernateInitServlet.init(HibernateInitServlet.java:46)
at javax.servlet.GenericServlet.init(GenericServlet.java:211)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1029)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:862)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4013)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4357)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:823)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:807)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:595)
at org.apache.catalina.core.StandardHostDeployer.install(StandardHostDeployer.java:277)
at org.apache.catalina.core.StandardHost.install(StandardHost.java:832)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:701)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:432)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:983)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:349)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1091)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:789)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1083)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:478)
at org.apache.catalina.core.StandardService.start(StandardService.java:480)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:2313)
at org.apache.catalina.startup.Catalina.start(Catalina.java:556)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:287)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:425)
Initial SessionFactory creation failed.org.hibernate.MappingException
Name and version of the database you are using: Oracle 9i
The generated SQL (show_sql=true): N/A
Debug level Hibernate log excerpt: