-->
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.  [ 4 posts ] 
Author Message
 Post subject: Cannot generate classes with same name but distinct packages
PostPosted: Wed May 25, 2005 5:10 pm 
Regular
Regular

Joined: Mon Jun 14, 2004 1:42 pm
Posts: 80
Location: Brazil
Hibernate version:
Hibernate 3.0.3
Mapping documents:
Class1 with table Class1p on package pacotedois
Code:
<hibernate-mapping package="pacotedois">
   <class
      name="Class1"
      table="Class1p"
   >   
      <id
         column="idClass1"
         name="idClass1"
         type="java.lang.Integer"
      >
         <generator class="increment">
         </generator>
      </id>   
      <property
         name="attr1"
         column="attr1"

         type="string"
         not-null="true"
        >
      </property>

   </class>
</hibernate-mapping>

Class1 with table Class1 on package pacoteum
Code:
<hibernate-mapping package="pacoteum">
   <class
      name="Class1"
      table="Class1"
   >   
      <id
         column="idClass1"
         name="idClass1"
         type="java.lang.Integer"
      >
         <generator class="increment">
         </generator>
      </id>   
      <property
         name="field1"
         column="field1"

         type="java.lang.Integer"
         not-null="true"
        >
      </property>
   </class>
</hibernate-mapping>

Full stack trace of any exception that occurs:
org.eclipse.core.runtime.CoreException[1]: D:\eclipse\runtime-workbench-workspace\MdrTest\genClasses.xml:15: Failed in building configuration when adding D:\eclipse\runtime-workbench-workspace\MdrTest\hbm\persistent\pacoteum\Class1.hbm
at org.hibernate.tool.ant.ConfigurationTask.addFile(ConfigurationTask.java:112)
at org.hibernate.tool.ant.ConfigurationTask.addMappings(ConfigurationTask.java:91)
at org.hibernate.tool.ant.ConfigurationTask.doConfiguration(ConfigurationTask.java:77)
at org.hibernate.tool.ant.ConfigurationTask.getConfiguration(ConfigurationTask.java:50)
at org.hibernate.tool.ant.HibernateToolTask.getConfiguration(HibernateToolTask.java:150)
at org.hibernate.tool.ant.Hbm2JavaGeneratorTask.execute(Hbm2JavaGeneratorTask.java:37)
at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:115)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
at org.apache.tools.ant.Task.perform(Task.java:364)
at org.apache.tools.ant.Target.execute(Target.java:341)
at org.apache.tools.ant.Target.performTasks(Target.java:369)
at org.apache.tools.ant.Project.executeTarget(Project.java:1214)
at org.eclipse.ant.internal.core.ant.InternalAntRunner.run(InternalAntRunner.java:635)
at org.eclipse.ant.internal.core.ant.InternalAntRunner.run(InternalAntRunner.java:412)
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.eclipse.ant.core.AntRunner.run(AntRunner.java:350)
at org.jtri.tool.popup.actions.GenHbmClasses.run(GenHbmClasses.java:109)
at org.eclipse.ui.internal.PluginAction.runWithEvent(PluginAction.java:276)
at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:915)
at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:866)
at org.eclipse.jface.action.ActionContributionItem$7.handleEvent(ActionContributionItem.java:785)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:82)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:796)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:2772)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2431)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1377)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1348)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:254)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:141)
at org.eclipse.ui.internal.ide.IDEApplication.run(IDEApplication.java:96)
at org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:335)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:273)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:129)
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.eclipse.core.launcher.Main.basicRun(Main.java:185)
at org.eclipse.core.launcher.Main.run(Main.java:704)
at org.eclipse.core.launcher.Main.main(Main.java:688)
Caused by: org.hibernate.MappingException: Could not configure datastore from file: D:\eclipse\runtime-workbench-workspace\MdrTest\hbm\persistent\pacoteum\Class1.hbm
at org.hibernate.cfg.Configuration.addFile(Configuration.java:247)
at org.hibernate.tool.ant.ConfigurationTask.addFile(ConfigurationTask.java:108)
... 42 more
Caused by: org.hibernate.MappingException: duplicate import: Class1
at org.hibernate.cfg.Mappings.addImport(Mappings.java:101)
at org.hibernate.cfg.HbmBinder.bindPersistentClassCommonValues(HbmBinder.java:542)
at org.hibernate.cfg.HbmBinder.bindClass(HbmBinder.java:487)
at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:233)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:151)
at org.hibernate.cfg.Configuration.add(Configuration.java:360)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:397)
at org.hibernate.cfg.Configuration.addFile(Configuration.java:243)
... 43 more
--- Nested Exception ---
org.hibernate.MappingException: Could not configure datastore from file: D:\eclipse\runtime-workbench-workspace\MdrTest\hbm\persistent\pacoteum\Class1.hbm
at org.hibernate.cfg.Configuration.addFile(Configuration.java:247)
at org.hibernate.tool.ant.ConfigurationTask.addFile(ConfigurationTask.java:108)
at org.hibernate.tool.ant.ConfigurationTask.addMappings(ConfigurationTask.java:91)
at org.hibernate.tool.ant.ConfigurationTask.doConfiguration(ConfigurationTask.java:77)
at org.hibernate.tool.ant.ConfigurationTask.getConfiguration(ConfigurationTask.java:50)
at org.hibernate.tool.ant.HibernateToolTask.getConfiguration(HibernateToolTask.java:150)
at org.hibernate.tool.ant.Hbm2JavaGeneratorTask.execute(Hbm2JavaGeneratorTask.java:37)
at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:115)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
at org.apache.tools.ant.Task.perform(Task.java:364)
at org.apache.tools.ant.Target.execute(Target.java:341)
at org.apache.tools.ant.Target.performTasks(Target.java:369)
at org.apache.tools.ant.Project.executeTarget(Project.java:1214)
at org.eclipse.ant.internal.core.ant.InternalAntRunner.run(InternalAntRunner.java:635)
at org.eclipse.ant.internal.core.ant.InternalAntRunner.run(InternalAntRunner.java:412)
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.eclipse.ant.core.AntRunner.run(AntRunner.java:350)
at org.jtri.tool.popup.actions.GenHbmClasses.run(GenHbmClasses.java:109)
at org.eclipse.ui.internal.PluginAction.runWithEvent(PluginAction.java:276)
at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:915)
at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:866)
at org.eclipse.jface.action.ActionContributionItem$7.handleEvent(ActionContributionItem.java:785)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:82)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:796)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:2772)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2431)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1377)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1348)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:254)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:141)
at org.eclipse.ui.internal.ide.IDEApplication.run(IDEApplication.java:96)
at org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:335)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:273)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:129)
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.eclipse.core.launcher.Main.basicRun(Main.java:185)
at org.eclipse.core.launcher.Main.run(Main.java:704)
at org.eclipse.core.launcher.Main.main(Main.java:688)
Caused by: org.hibernate.MappingException: duplicate import: Class1
at org.hibernate.cfg.Mappings.addImport(Mappings.java:101)
at org.hibernate.cfg.HbmBinder.bindPersistentClassCommonValues(HbmBinder.java:542)
at org.hibernate.cfg.HbmBinder.bindClass(HbmBinder.java:487)
at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:233)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:151)
at org.hibernate.cfg.Configuration.add(Configuration.java:360)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:397)
at org.hibernate.cfg.Configuration.addFile(Configuration.java:243)
Comments:

It's today's checked out hbm2java ant task (hibernate 3) from sourcesafe. I had never tried before 2 classes with same name but distinct tables and packages on hibernate, and I don't know if it's a know limitation or a bug, or maybe something that I'm not doing right ;)
But I thought it may be a situtation that may happen in a large system.

Thanks

_________________
Alexandre Torres
--------------------


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 25, 2005 6:32 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
that is an illegal hibernate mapping! you need to use entity-name to have the same class mapped twice. (btw. i actually dont know how hbm2java will react on this since it would need to merge these two classes to get the proper mapping)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 26, 2005 1:02 pm 
Regular
Regular

Joined: Mon Jun 14, 2004 1:42 pm
Posts: 80
Location: Brazil
But it´s not the same class, that's two different classes that happens to have the same name (but not package), each in a different hbm file and table and methods and so on. What identifies a java class is not only it´s name but name+package right ? (at least in java language)
I haven´t tried entity-name yet, but seems to be for another propouse (using maps instead of classes or mapping a class to two tables ?)
is package1.Class1 == package2.Class1 ?
Thanks

_________________
Alexandre Torres
--------------------


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 26, 2005 5:01 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
if you have non-unique class names (without the package name) you will have to disable auto-import for one of them.

-max

_________________
Max
Don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.