-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Mapping exception: Duplicate named query
PostPosted: Thu Jan 31, 2008 4:28 pm 
Newbie

Joined: Thu Jan 31, 2008 2:55 pm
Posts: 2
I have a project aiming to use standard JPA data access technology. We're evaluating certain persistence providers right now and have been trying ToplinkEssentials already. As it shows some flaws here and there Hibernate is the next candidate of choice.

I describe one named query in orm.xml:

Code:
<named-query name="User.findByUsername">
   <query>SELECT u FROM User u WHERE u.username = ?1</query>
</named-query>


I do not use @NamedQuery anywhere, so it is the only named query in the entire project. Nevertheless I get

org.hibernate.DuplicateMappingException: Duplicate query mapping User.findByUsername

Here is the stacktrace:
Code:
21:25:26,656  INFO LocalContainerEntityManagerFactoryBean:218 - Building JPA container EntityManagerFactory for persistence unit 'minos'
21:25:26,686  INFO Version:15 - Hibernate Annotations 3.3.0.GA
21:25:26,700  INFO Environment:514 - Hibernate 3.2.5
21:25:26,704  INFO Environment:547 - hibernate.properties not found
21:25:26,705  INFO Environment:681 - Bytecode provider name : cglib
21:25:26,710  INFO Environment:598 - using JDK 1.4 java.sql.Timestamp handling
21:25:26,768  INFO Version:15 - Hibernate EntityManager 3.3.1.GA
21:25:26,790 DEBUG Ejb3Configuration:302 - Processing PersistenceUnitInfo [
   name: minos
   persistence provider classname: null
   classloader: sun.misc.Launcher$AppClassLoader@33056f
   Temporary classloader: org.springframework.instrument.classloading.SimpleThrowawayClassLoader@cf3710
   excludeUnlistedClasses: false
   JTA datasource: null
   Non JTA datasource: org.apache.commons.dbcp.BasicDataSource@280492
   Transaction type: RESOURCE_LOCAL
   PU root URL: file:/Users/olivergierke/Documents/workspace/minos-core/target/classes/
   Jar files URLs [
      file:/Users/olivergierke/Documents/workspace/minos-core/target/classes/]
   Managed classes names [
      com.synyx.minos.core.domain.AbstractEntity
      com.synyx.minos.core.domain.User
      com.synyx.minos.core.domain.Role]
   Mapping files names []
   Properties []
21:25:26,790 DEBUG Ejb3Configuration:553 - Detect class: true; detect hbm: true
21:25:26,791 DEBUG Ejb3Configuration:553 - Detect class: true; detect hbm: true
21:25:26,853  INFO Ejb3Configuration:678 - found EJB3 @MappedSuperclass: com.synyx.minos.core.domain.AbstractEntity
21:25:26,855  INFO Ejb3Configuration:668 - found EJB3 Entity bean: com.synyx.minos.core.domain.Role
21:25:26,856  INFO Ejb3Configuration:668 - found EJB3 Entity bean: com.synyx.minos.core.domain.User
21:25:26,880  INFO Ejb3Configuration:678 - found EJB3 @MappedSuperclass: com.synyx.minos.core.domain.AbstractEntity
21:25:26,881  INFO Ejb3Configuration:668 - found EJB3 Entity bean: com.synyx.minos.core.domain.Role
21:25:26,882  INFO Ejb3Configuration:668 - found EJB3 Entity bean: com.synyx.minos.core.domain.User
21:25:26,933 DEBUG DTDEntityResolver:38 - trying to resolve system-id [file:///Users/olivergierke/Documents/workspace/minos-core/orm_1_0.xsd]
21:25:26,933 DEBUG EJB3DTDEntityResolver:31 - recognized EJB3 ORM namespace; attempting to resolve on classpath under org/hibernate/ejb
21:25:26,934 DEBUG EJB3DTDEntityResolver:40 - located [file:///Users/olivergierke/Documents/workspace/minos-core/orm_1_0.xsd] in classpath
21:25:26,998 DEBUG DTDEntityResolver:38 - trying to resolve system-id [file:///Users/olivergierke/Documents/workspace/minos-core/orm_1_0.xsd]
21:25:26,998 DEBUG EJB3DTDEntityResolver:31 - recognized EJB3 ORM namespace; attempting to resolve on classpath under org/hibernate/ejb
21:25:27,000 DEBUG EJB3DTDEntityResolver:40 - located [file:///Users/olivergierke/Documents/workspace/minos-core/orm_1_0.xsd] in classpath
21:25:27,079 DEBUG AnnotationConfiguration:244 - Execute first pass mapping processing
21:25:27,175  INFO QueryBinder:64 - Binding Named query: User.findByUsername => SELECT u FROM User u WHERE u.username = ?1
21:25:27,177  INFO DefaultListableBeanFactory:340 - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@12d7ae: defining beans [org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0,dataSource,persistenceUnitManager,entityManagerFactory,org.springframework.orm.jpa.JpaTransactionManager#0]; root of factory hierarchy


Any ideas?

Thanks in advance...
Ollie


Top
 Profile  
 
 Post subject: Re:Duplicate query mapping User.findByUsername
PostPosted: Sat Mar 07, 2009 6:36 pm 
Newbie

Joined: Wed Nov 19, 2008 3:30 pm
Posts: 3
I'd be interested in getting an answer to this one also. I'm having exactly the same error, also on my User entity. I tried naming the query with random characters but I still get an error from the compiler (Eclipse 3.4) even before I try to run the project.


Top
 Profile  
 
 Post subject: Re:Duplicate query mapping User.findByUsername
PostPosted: Sat Mar 07, 2009 7:38 pm 
Newbie

Joined: Wed Nov 19, 2008 3:30 pm
Posts: 3
I think I've found the answer to this. Apparently, in order to define a NamedQuery (either globally in the orm.xml file or with annotations on the Entity class) the entity must be mapped in the orm.xml file. If you map the entity in the persistence.xml file, and not in orm.xml, then you get this error.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.