I tried to follow the Hibernate Tutorial posted on official Hibernate site. Here is the link to the tutorial. I was using Apache Maven version 2.2.1 and I had to make a lot of modifications to the tutorial code (specially in pom.xml) to make it work. I want to post these fixes/code updates and maybe it might help someone who is having problems walking through the tutorial.
There were so many issues and the post was getting big so I am splitting it into different posts. you can skip reading the 'preface' section of the other posts in this series.
Problem 6 of 6:
Error in hibernate mapping file
I was able to Store and display Events. I added the Person and all the mappings to represent the many-to-many relationship between the Person and the Event. Then I tried to execute the EventManager once more, to create and add a Person to an Event, by running the following command:
mvn -e exec:java -Dexec.mainClass="org.hibernate.tutorial.EventFactory" -Dexec.args="addpersontoevent"
I was getting the following error:
+ Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'exec'.
[INFO] ------------------------------------------------------------------------
[INFO] Building First hibernate tutorials
[INFO] task-segment: [exec:java]
[INFO] ------------------------------------------------------------------------
[INFO] Preparing exec:java
[INFO] No goals needed for project - skipping
[INFO] [exec:java {execution: default-cli}]
>>>>>>>>>>>>>>>>>> args[0]: add
>>>>>>>>>>>>>>>>>> in createAndStoreEvent()...
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] An exception occured while executing the Java class. null
An association from the table PERSON_EVENTS refers to an unmapped class: events.Person
[INFO] ------------------------------------------------------------------------
[INFO] Trace
org.apache.maven.lifecycle.LifecycleExecutionException: An exception occured while executing the Java class. null
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:719)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:569)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:539)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
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:597)
at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: org.apache.maven.plugin.MojoExecutionException: An exception occured while executing the Java class. null
at org.codehaus.mojo.exec.ExecJavaMojo.execute(ExecJavaMojo.java:338)
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
... 17 more
Caused by: java.lang.reflect.InvocationTargetException
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:597)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:283)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.ExceptionInInitializerError
at org.hibernate.tutorial.util.HibernateUtil.buildSessionFactory(HibernateUtil.java:16)
at org.hibernate.tutorial.util.HibernateUtil.(HibernateUtil.java:9)
at org.hibernate.tutorial.EventManager.createAndStoreEvent(EventManager.java:46)
at org.hibernate.tutorial.EventManager.main(EventManager.java:22)
... 6 more
Caused by: org.hibernate.MappingException: An association from the table PERSON_EVENTS refers to an unmapped class: events.Person
at org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:1285)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1203)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1319)
at org.hibernate.tutorial.util.HibernateUtil.buildSessionFactory(HibernateUtil.java:13)
... 9 more
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 second
[INFO] Finished at: Tue May 11 18:52:58 PDT 2010
[INFO] Final Memory: 5M/15M
[INFO] ------------------------------------------------------------------------
The culprit here is the usage of wrong class name in the Event.hbm.xml. The tutorial code is:
It should be:
That's all the bugs I found in the tutorial. I also setup MySQL DB and configured hibernate to use it instead of HSQLDB. Please see my next post for those details.
No comments:
Post a Comment