-->
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.  [ 6 posts ] 
Author Message
 Post subject: Cobertura mag meine Hibernate Config nicht
PostPosted: Thu Jul 03, 2008 7:00 pm 
Newbie

Joined: Wed Jul 02, 2008 8:44 pm
Posts: 14
Location: Zurich, Switzerland
Also ich benutz momentan Maven 2 um mein Projekt zu bauen, meine Unit tests laufen wunderbar durch nur wenn ich die Cobertura tests durchlaufen lassen will findet Maven die Klassen die mit Hibernate gemappt werden nicht mehr:
Code:
[cxd@nex:myproject]$ mvn cobertura:check
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'cobertura'.
[INFO] ------------------------------------------------------------------------
[INFO] Building myproject
[INFO]    task-segment: [cobertura:check]
[INFO] ------------------------------------------------------------------------
[INFO] Preparing cobertura:check
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:compile]
[INFO] Nothing to compile - all classes are up to date
[INFO] [cobertura:instrument]
[INFO] Cobertura 1.9 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file
Cobertura: Loaded information on 17 classes.
Instrumenting 17 files to /home/cxd/dev/myproject/target/generated-classes/cobertura
Cobertura: Saved information on 17 classes.
Instrument time: 931ms

[INFO] Instrumentation was successful.
[INFO] [resources:testResources]
[INFO] Using default encoding to copy filtered resources.
[INFO] Preparing hibernate3:hbm2ddl
[WARNING] Removing: hbm2ddl from forked lifecycle, to prevent recursive invocation.
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [hibernate3:hbm2ddl {execution: default}]
[INFO] src/main/resources/hibernate.cfg.xml not found within the project. Trying absolute path.
[INFO] Configuration XML file loaded: file:/home/cxd/dev/myproject/target/test-classes/hibernate.cfg.xml
00:57:43,804  INFO org.hibernate.cfg.annotations.Version - Hibernate Annotations 3.3.0.GA
00:57:43,819  INFO org.hibernate.cfg.Environment - Hibernate 3.2.5
00:57:43,822  INFO org.hibernate.cfg.Environment - hibernate.properties not found
00:57:43,824  INFO org.hibernate.cfg.Environment - Bytecode provider name : cglib
00:57:43,827  INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
[INFO] src/main/resources/hibernate.cfg.xml not found within the project. Trying absolute path.
[INFO] Configuration XML file loaded: file:/home/cxd/dev/myproject/target/test-classes/hibernate.cfg.xml
00:57:43,892  INFO org.hibernate.cfg.Configuration - configuring from url: file:/home/cxd/dev/myproject/target/test-classes/hibernate.cfg.xml
[INFO] ------------------------------------------------------------------------
[ERROR] FATAL ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Unable to load class declared as <mapping class="myproject.model.User"/> in the configuration:
[INFO] ------------------------------------------------------------------------
[INFO] Trace
org.hibernate.MappingException: Unable to load class declared as <mapping class="myproject.model.User"/> in the configuration:
        at org.hibernate.cfg.AnnotationConfiguration.parseMappingElement(AnnotationConfiguration.java:602)
        at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1555)
        at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1534)
        at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1508)
        at org.hibernate.cfg.Configuration.configure(Configuration.java:1443)
        at org.codehaus.mojo.hibernate3.configuration.AbstractComponentConfiguration.doConfiguration(AbstractComponentConfiguration.java:77)
        at org.codehaus.mojo.hibernate3.configuration.AbstractComponentConfiguration.getConfiguration(AbstractComponentConfiguration.java:40)
        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:447)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:539)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:480)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.forkProjectLifecycle(DefaultLifecycleExecutor.java:896)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.forkLifecycle(DefaultLifecycleExecutor.java:739)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:510)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:493)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:463)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:311)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:278)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:143)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:333)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:126)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:282)
        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: java.lang.ClassNotFoundException: myproject.model.User
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at org.codehaus.classworlds.RealmClassLoader.loadClassDirect(RealmClassLoader.java:195)
        at org.codehaus.classworlds.DefaultClassRealm.loadClass(DefaultClassRealm.java:255)
        at org.codehaus.classworlds.DefaultClassRealm.loadClass(DefaultClassRealm.java:274)
        at org.codehaus.classworlds.RealmClassLoader.loadClass(RealmClassLoader.java:214)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:169)
        at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:100)
        at org.hibernate.cfg.AnnotationConfiguration.parseMappingElement(AnnotationConfiguration.java:599)
        ... 30 more
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6 seconds
[INFO] Finished at: Fri Jul 04 00:57:44 CEST 2008
[INFO] Final Memory: 9M/17M
[INFO] ------------------------------------------------------------------------

Hat das Problem schonmal jemand gehabt?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 09, 2008 6:52 pm 
Senior
Senior

Joined: Mon Jul 07, 2008 4:35 pm
Posts: 141
Location: Berlin
Hi Snyke,

Quote:
org.hibernate.MappingException: Unable to load class declared as <mapping class="myproject.model.User"/> in the configuration:

Das mit dem Finden vom Mapping-Dateien scheint manchmal recht unintuitiv zu sein, so meine Erfahrung. Hab manchmal das Gefühl, dass das mit dem CLASSPATH nicht so ganz stimmt.

Lösungsversuch 1:
Eine Mapping Datei muss, glaub ich, die Endung .hbm.xml (in Deinem Falle also User.hbm.xml) haben. Das muss auch in dem XML-Tag mitsamt der Endung stehen.

Lösungsversuch 2:
Vom Ort deiner hibernate.cfg.xml gibst du mal den relativen Pfad (also mit "/" (forward slashes) anstatt "." (Punkten)) zur Mapping-Datei ein (also etwa <mapping class="myproject/model/User"/>). Das würde bedeuten, dass deine hibernate.cfg.xml im gleichen Verzeichnis wie myproject/ liegt.

Lösungsversuch 3:
<mapping class="classpath:User_Mapping_File"/>, da ja vermutlich die Datei innerhalb deines CLASSPATH liegt... (User_Mapping_File übrigens mit dem realen Dateinamen des Mapping-Files ersetzen)

CU
Froestel

_________________
Have you tried turning it off and on again? [Roy]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 10, 2008 10:18 am 
Newbie

Joined: Wed Jul 02, 2008 8:44 pm
Posts: 14
Location: Zurich, Switzerland
Naja das Problem is nicht dass es die mappings nicht findet sondern die Javaklassen mit den Annotations nicht findet.


Top
 Profile  
 
 Post subject: hibernate error with cobertura instrument
PostPosted: Thu Jul 10, 2008 8:58 pm 
Newbie

Joined: Thu Jul 10, 2008 8:50 pm
Posts: 2
I read the translated page. Question in English:
I am having the same problem. My tests run successfully without cobertura but fail when I run mvn cobertura:cobertura
Did anyone have a solution to this? I could not see it posted.
Thanks Jol.

[INFO] [cobertura:instrument]
............
run tests:

WARN logExceptions, SQL Error: 0, SQLState: null
ERROR logExceptions, failed batch
ERROR performExecutions, Could not synchronize database state with session
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:253)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at au.com.observant.ringocore.dao.BaseRingoCoreDAO.baseSave(BaseRingoCoreDAO.java:183)
at au.com.observant.ringocore.dao.hibernate.HibernateRoleDAO.save(HibernateRoleDAO.java:72)
at au.com.observant.ringocore.dao.hibernate.HibernateRoleDAO.save(HibernateRoleDAO.java:19)
at au.com.observant.ringocore.dao.hibernate.HibernateRoleDAOTest.testSaveRolesWithTheSameName(HibernateRoleDAOTest.java:216)
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:585)
at junit.framework.TestCase.runTest(TestCase.java:164)
at junit.framework.TestCase.runBare(TestCase.java:130)
at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:69)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:120)
at junit.framework.TestSuite.runTest(TestSuite.java:228)
at junit.framework.TestSuite.run(TestSuite.java:223)
at org.junit.internal.runners.OldTestClassRunner.run(OldTestClassRunner.java:35)
at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
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:585)
at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:338)
at org.apache.maven.surefire.booter.SurefireBooter.run(SurefireBooter.java:241)
at org.apache.maven.plugin.surefire.SurefirePlugin.execute(SurefirePlugin.java:492)
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:451)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:558)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:499)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.forkProjectLifecycle(DefaultLifecycleExecutor.java:924)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.forkLifecycle(DefaultLifecycleExecutor.java:767)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:529)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:512)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:482)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:330)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:291)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:142)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:336)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:129)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:287)
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:585)
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: java.sql.BatchUpdateException: failed batch
at org.hsqldb.jdbc.jdbcStatement.executeBatch(Unknown Source)
at org.hsqldb.jdbc.jdbcPreparedStatement.executeBatch(Unknown Source)
at org.apache.commons.dbcp.DelegatingStatement.executeBatch(DelegatingStatement.java:294)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
... 58 more


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 10, 2008 9:16 pm 
Newbie

Joined: Wed Jul 02, 2008 8:44 pm
Posts: 14
Location: Zurich, Switzerland
Hi again, I actually solved my own problem by changing the hibernate-plugin configuration by this:
Code:
         <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>hibernate3-maven-plugin</artifactId>
            <version>2.1</version>
            <configuration>
               <components>
                  <component>
                     <name>hbm2ddl</name>
                     <implementation>annotationconfiguration</implementation>
                  </component>
               </components>
               <componentProperties>
                  <drop>false</drop>
                  <jdk5>true</jdk5>
                  <configurationfile>target/classes/hibernate.cfg.xml</configurationfile>
                  <skip>true</skip>
               </componentProperties>
            </configuration>
            <executions>
               <execution>
                  <phase>process-test-resources</phase>
                  <goals>
                     <goal>hbm2ddl</goal>
                  </goals>
               </execution>
            </executions>
            <dependencies>
               <dependency>
                  <groupId>${jdbc.groupId}</groupId>
                  <artifactId>${jdbc.artifactId}</artifactId>
                  <version>${jdbc.version}</version>
               </dependency>
            </dependencies>
         </plugin>

Notice the <skip>true</skip> part in the compontentProperties, actually I have no clue what that's for, but it solved the problem ^^


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 10, 2008 9:36 pm 
Newbie

Joined: Thu Jul 10, 2008 8:50 pm
Posts: 2
I just found this possible cause in
http://cobertura.sourceforge.net/faq.html

Cobertura uses ASM to modify your bytecode. There are a few other popular programs that use ASM; Groovy and *Hibernate*, to name two. You could have problems if Cobertura uses a different version of asm and you add both versions to your classpath.


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