facebook

Error using hql file (DuplicateMappingException)

  1. MyEclipse Archived
  2.  > 
  3. Database Tools (DB Explorer, Hibernate, etc.)
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #295573 Reply

    msc
    Member

    I have a problem when I try to test hql querys in a hql file. The exception I get is:

    
    org.hibernate.DuplicateMappingException: Duplicate query mapping user.login
        at org.hibernate.cfg.Mappings.checkQueryExist(Mappings.java:270)
        at org.hibernate.cfg.Mappings.addQuery(Mappings.java:259)
        at org.hibernate.cfg.ExtendedMappings.addQuery(ExtendedMappings.java:249)
        at org.hibernate.cfg.annotations.QueryBinder.bindQuery(QueryBinder.java:62)
        at org.hibernate.cfg.annotations.QueryBinder.bindQueries(QueryBinder.java:190)
        at org.hibernate.cfg.AnnotationBinder.bindQueries(AnnotationBinder.java:267)
        at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:417)
        at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:498)
        at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:277)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1286)
        at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:915)
        at org.hibernate.console.ConsoleConfiguration$3.execute(ConsoleConfiguration.java:362)
        at org.hibernate.console.execution.DefaultExecutionContext.execute(DefaultExecutionContext.java:65)
        at org.hibernate.console.ConsoleConfiguration.execute(ConsoleConfiguration.java:91)
        at org.hibernate.console.ConsoleConfiguration.buildSessionFactory(ConsoleConfiguration.java:357)
        at com.genuitec.eclipse.hibernate.wizards.MEConsoleConfiguration.buildSessionFactory(MEConsoleConfiguration.java:234)
        at com.genuitec.eclipse.hibernate.action.MERefreshCCAction.buildSessionFactory(MERefreshCCAction.java:121)
        at com.genuitec.eclipse.hibernate.action.MEExecuteHQLAction.run(MEExecuteHQLAction.java:67)
        at org.eclipse.jface.action.Action.runWithEvent(Action.java:498)
        at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:583)
        at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:500)
        at org.eclipse.jface.action.ActionContributionItem$6.handleEvent(ActionContributionItem.java:452)
        at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
        at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
        at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3823)
        at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3422)
        at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2382)
        at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2346)
        at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2198)
        at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:493)
        at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:288)
        at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:488)
        at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
        at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:113)
        at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:193)
        at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
        at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
        at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:386)
        at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:549)
        at org.eclipse.equinox.launcher.Main.basicRun(Main.java:504)
        at org.eclipse.equinox.launcher.Main.run(Main.java:1236)
    

    “user.login” is a named query as an annotation in my java class:

    
    @Entity
    @Table(name="tUser")
    @NamedQueries({
        @NamedQuery(name="user.login", query="from User u where u.username = ? and u.password = ?"),
        @NamedQuery(name="user.unique", query="from User u where u.username = ?")
    })
    public class User implements Serializable{
    .
    .
    .
    

    If I remove the user.login query, the same exception occures for “user.unique”. It seems like the configuration is read twice, but I really don’t know why. Here’s my mapping file

    
    <?xml version='1.0' encoding='UTF-8'?>
    <!DOCTYPE hibernate-configuration PUBLIC
              "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
              "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
    
    <!-- Generated by MyEclipse Hibernate Tools.                   -->
    <hibernate-configuration>
    
    <session-factory>
        <property name="connection.username">pollerUser</property>
        <property name="connection.url">
            jdbc:<myurl>
        </property>
        <property name="dialect">
            org.hibernate.dialect.SQLServerDialect
        </property>
        <property name="connection.password"><mypass></property>
        <property name="connection.driver_class">
            com.microsoft.jdbc.sqlserver.SQLServerDriver
        </property>
        <property name="hbm2ddl.auto">update</property>
    
        <mapping class="ch.ims.pen.poller.persistent.User" />
        <mapping class="ch.ims.pen.poller.persistent.Role" />
        <mapping class="ch.ims.pen.poller.persistent.Event" />
        <mapping class="ch.ims.pen.poller.persistent.Reservation" />
        <mapping class="ch.ims.pen.poller.persistent.AbstractPlugin" />
        <mapping class="ch.ims.pen.poller.persistent.DemoFormInstance" />
    
    </session-factory>
    
    </hibernate-configuration>
    

    Does anyone have an idea?
    Thank you very much!!

    #295595 Reply

    Brian Fernandes
    Moderator

    I tried something similar locally with Named queries but could not reproduce the problem. I have a few questions:

    1) Does this application work if you run / deploy it?
    2) Does the HQL Editor work for you if you remove both queries?
    3) Is your User class being extended by any of the other mapped classes?
    4) Do you have any other mapping files (.hbm.xml or hibernate.properties) files in your project? Any other place where you could have declared this query in the same project?

    #295606 Reply

    msc
    Member

    Ok, I managed to execute a query now with a workaround. But here the answers to your questions before the explanation of what I did.

    1) Yes, the application can be deployed without any problems
    2) No. If I remove both queries the Exception I get is:

    
    org.hibernate.DuplicateMappingException: Duplicate class/entity mapping ch.ims.pen.poller.persistent.User
        at org.hibernate.cfg.Mappings.addClass(Mappings.java:118)
        at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:769)
        at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:498)
        at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:277)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1286)
        at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:915)
        at org.hibernate.console.ConsoleConfiguration$3.execute(ConsoleConfiguration.java:362)
        at org.hibernate.console.execution.DefaultExecutionContext.execute(DefaultExecutionContext.java:65)
        at org.hibernate.console.ConsoleConfiguration.execute(ConsoleConfiguration.java:91)
        at org.hibernate.console.ConsoleConfiguration.buildSessionFactory(ConsoleConfiguration.java:357)
        at com.genuitec.eclipse.hibernate.wizards.MEConsoleConfiguration.buildSessionFactory(MEConsoleConfiguration.java:234)
        at com.genuitec.eclipse.hibernate.action.MERefreshCCAction.buildSessionFactory(MERefreshCCAction.java:121)
        at com.genuitec.eclipse.hibernate.action.MEExecuteHQLAction.run(MEExecuteHQLAction.java:67)
        at org.eclipse.jface.action.Action.runWithEvent(Action.java:498)
        at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:583)
        at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:500)
        at org.eclipse.jface.action.ActionContributionItem$6.handleEvent(ActionContributionItem.java:452)
        at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
        at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
        at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3823)
        at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3422)
        at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2382)
        at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2346)
        at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2198)
        at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:493)
        at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:288)
        at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:488)
        at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
        at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:113)
        at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:193)
        at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
        at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
        at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:386)
        at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:549)
        at org.eclipse.equinox.launcher.Main.basicRun(Main.java:504)
        at org.eclipse.equinox.launcher.Main.run(Main.java:1236)
    

    If I remove the class User from my hibernate configuration, the same exception occures for the next defined class.

    3) No.
    4) No.

    In the hibernate configuration are classes which are implemented in another project/module. So I copied the those compiled classes (only classes, no other config files) manually to the classpath of the project where I have the mapping. This might not be a good practice but I just wanted to test a hql query quickly. Apparantly this step generated the exception above. (Sorry, it’s difficult to explain…)
    To test my query, I just removed these classes from the mapping file because they weren’t used here. And it worked…

    Thanks for your support

    #295612 Reply

    Brian Fernandes
    Moderator

    Yes, if you have the same classes multiple times in your project’s classpath (I assume this project is dependent on the project you copied from?), you could see this sort of problem. Glad it’s working now.

Viewing 4 posts - 1 through 4 (of 4 total)
Reply To: Error using hql file (DuplicateMappingException)

You must be logged in to post in the forum log in