Hi,

use version 2.2 of the plugin hibernate3-maven-plugin



Rishabh Joshi wrote:
> 
> Hi,
> 
> I am building a simple application using Hibernate and Maven.
> I came across your plugin "hibernate3:hbm2ddl" which generates the tables
> in the database. But, upon using it I get following exception:
> 
> ~EXCEPTION~
> [INFO] [hibernate3:hbm2ddl]
> 16:11:26,735  INFO org.hibernate.cfg.Environment - Hibernate 3.2.0.cr5
> 16:11:26,735  INFO org.hibernate.cfg.Environment - hibernate.properties
> not found
> 16:11:26,766  INFO org.hibernate.cfg.Environment - Bytecode provider name
> : cglib
> 16:11:26,766  INFO org.hibernate.cfg.Environment - using JDK 1.4
> java.sql.Timestamp handling
> [INFO] Configuration XML file loaded:
> E:\Rishabh\Projects\Learning\auctionapp\src\main\resources\hibernate.cfg.xml
> 16:11:26,813  INFO org.hibernate.cfg.Configuration - configuring from
> file: hibernate.cfg.xml
> 16:11:26,985  INFO org.hibernate.cfg.Configuration - Reading mappings from
> resource: com/learning/app/model/BaseModel.hbm.xml
> 16:11:27,126  INFO org.hibernate.cfg.HbmBinder - Mapping class:
> com.learning.app.model.BaseModel -> BaseModel
> 16:11:27,188  INFO org.hibernate.cfg.HbmBinder - Mapping union-subclass:
> com.learning.app.model.User -> USER
> 16:11:27,204  INFO org.hibernate.cfg.HbmBinder - Mapping union-subclass:
> com.learning.app.model.Role -> ROLE
> 16:11:27,204  INFO org.hibernate.cfg.Configuration - Configured
> SessionFactory: null
> 16:11:27,204  INFO org.hibernate.cfg.Configuration - Reading mappings from
> file:
> E:\Rishabh\Projects\Learning\auctionapp\target\classes\com\learning\app\model\BaseModel.hbm.xml
> [INFO] src/main/resources/database.properties not found within the
> project. Trying absolute path.
> [INFO] No hibernate properties file loaded.
> 16:11:27,251  INFO org.hibernate.cfg.Mappings - duplicate import:
> com.learning.app.model.BaseModel->com.learning.app.model.BaseModel
> 16:11:27,251  INFO org.hibernate.cfg.Mappings - duplicate import:
> com.learning.app.model.BaseModel->BaseModel
> 16:11:27,251  INFO org.hibernate.cfg.HbmBinder - Mapping class:
> com.learning.app.model.BaseModel -> BaseModel
> 16:11:27,251  INFO org.hibernate.cfg.Mappings - duplicate import:
> com.learning.app.model.User->com.learning.app.model.User
> 16:11:27,251  INFO org.hibernate.cfg.Mappings - duplicate import:
> com.learning.app.model.User->User
> Exception in thread "main" org.hibernate.InvalidMappingException: Could
> not parse mapping document from file
> E:\Rishabh\Projects\Learning\auctionapp\target\classes\com\learning\app\model\BaseModel.hbm.xml
>       at org.hibernate.cfg.Configuration.addFile(Configuration.java:306)
>       at org.hibernate.cfg.Configuration.addDirectory(Configuration.java:623)
>       at org.hibernate.cfg.Configuration.addDirectory(Configuration.java:620)
>       at org.hibernate.cfg.Configuration.addDirectory(Configuration.java:620)
>       at org.hibernate.cfg.Configuration.addDirectory(Configuration.java:620)
>       at org.hibernate.cfg.Configuration.addDirectory(Configuration.java:620)
>       at
> org.codehaus.mojo.hibernate3.configuration.DefaultComponentConfiguration.doConfiguration(DefaultComponentConfiguration.java:30)
>       at
> org.codehaus.mojo.hibernate3.configuration.AbstractComponentConfiguration.getConfiguration(AbstractComponentConfiguration.java:37)
>       at
> org.codehaus.mojo.hibernate3.exporter.Hbm2DDLExporterMojo.doExecute(Hbm2DDLExporterMojo.java:87)
>       at
> org.codehaus.mojo.hibernate3.HibernateExporterMojo.execute(HibernateExporterMojo.java:140)
>       at
> org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:579)
>       at
> org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:498)
>       at
> org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegmentForProject(DefaultLifecycleExecutor.java:265)
>       at
> org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:191)
>       at
> org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:149)
>       at
> org.apache.maven.DefaultMaven.execute_aroundBody0(DefaultMaven.java:223)
>       at
> org.apache.maven.DefaultMaven.execute_aroundBody1$advice(DefaultMaven.java:304)
>       at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:1)
>       at
> org.apache.maven.embedder.MavenEmbedder.execute_aroundBody2(MavenEmbedder.java:904)
>       at
> org.apache.maven.embedder.MavenEmbedder.execute_aroundBody3$advice(MavenEmbedder.java:304)
>       at org.apache.maven.embedder.MavenEmbedder.execute(MavenEmbedder.java:1)
>       at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:176)
>       at org.apache.maven.cli.MavenCli.main(MavenCli.java:63)
>       at org.apache.maven.cli.MavenCli.main(MavenCli.java:52)
> Caused by: org.hibernate.DuplicateMappingException: Duplicate table
> mapping USER
>       at org.hibernate.cfg.Mappings.addDenormalizedTable(Mappings.java:192)
>       at org.hibernate.cfg.HbmBinder.bindUnionSubclass(HbmBinder.java:787)
>       at org.hibernate.cfg.HbmBinder.handleUnionSubclass(HbmBinder.java:2194)
>       at 
> org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2107)
>       at 
> org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2031)
>       at
> org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:359)
>       at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:273)
>       at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:144)
>       at org.hibernate.cfg.Configuration.add(Configuration.java:424)
>       at 
> org.hibernate.cfg.Configuration.addInputStream(Configuration.java:465)
>       at org.hibernate.cfg.Configuration.addFile(Configuration.java:303)
>       ... 23 more
> 
> 
> 
> What I noticed is that the plugin is loading my mapping file (*.hbm.xml)
> twice! If I remove the <mapping> tag from my configuration file
> (hibernate.cfg.xml) then everything works normally. Which means that my
> mapping file is searched for in the classpath and loaded, and if I specify
> it in the configuration file also then I get the above exception, for it
> has loaded it again.
> 
> Is there a way to prevent the auto-loading of the mapping files from the
> classpath and only load them when the plugin reads the configuration file?
> 
> Below is a portion of the pom.xml file.
> 
> ~POM.XML~
> ...
>             <plugin>
>                 <groupId>org.codehaus.mojo</groupId>
>                 <artifactId>hibernate3-maven-plugin</artifactId>
>                 <version>2.0-alpha-2</version>
>                 <configuration>
>                     <components>
>                         <component>
>                             <name>hbm2ddl</name>
>                             <implementation>configuration</implementation>
>                         </component>
>                     </components>
>                     <componentProperties>
>                         <drop>true</drop>
>                        
> <configurationfile>/src/main/resources/hibernate.cfg.xml</configurationfile>
>                         <outputfilename>schema.sql</outputfilename>
>                     </componentProperties>
>                     <executions>
>                         <execution>
>                             <phase>process-resources</phase>
>                             <goals>
>                                 <goal>hbm2ddl</goal>
>                             </goals>
>                         </execution>
>                     </executions>
>                 </configuration>
>                 <dependencies>
>                     <dependency>
>                         <groupId>mysql</groupId>
>                         <artifactId>mysql-connector-java</artifactId>
>                         <version>5.1.6</version>
>                     </dependency>
>                 </dependencies>
>             </plugin>
> ...
> 
> Regards,
> Rishabh
> 

-- 
View this message in context: 
http://www.nabble.com/Auto-loading-of-mapping-%28*.hbm.xml%29-files-causing-exception-tp21308535p21625117.html
Sent from the mojo - user mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to