• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

EJB3 UNIT - Class cast exception

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

i have been trying to implement the EJB3unit in my EJB project. when i am trying to test the session bean it throws the following exception, if you have any ideas please help me .thanks

java.lang.ClassCastException: org.ejb3unit.asm.jar.Type incompatible with org.ejb3unit.hibernate.asm.Type
at com.bm.ejb3metadata.annotations.analyzer.classes.JavaxEjbRemoteVisitor.visitEnd(JavaxEjbRemoteVisitor.java:36)
at org.ejb3unit.asm.jar.ClassReader.a(Unknown Source)
at org.ejb3unit.asm.jar.ClassReader.a(Unknown Source)
at org.ejb3unit.asm.jar.ClassReader.a(Unknown Source)
at org.ejb3unit.asm.jar.ClassReader.accept(Unknown Source)
at org.ejb3unit.asm.jar.ClassReader.accept(Unknown Source)
at com.bm.ejb3metadata.MetadataAnalyzer.read(MetadataAnalyzer.java:113)
at com.bm.ejb3metadata.MetadataAnalyzer.analyze(MetadataAnalyzer.java:79)
at com.bm.ejb3metadata.MetadataAnalyzer.analyzeClasses(MetadataAnalyzer.java:49)
at com.bm.ejb3metadata.MetadataAnalyzer.initialize(MetadataAnalyzer.java:36)
at com.bm.ejb3metadata.annotations.metadata.MetaDataCache.getMetaData(MetaDataCache.java:128)
at com.bm.ejb3metadata.annotations.metadata.MetaDataCache.getMockModuleCreator(MetaDataCache.java:152)
at com.bm.testsuite.mocked.MockedSessionBeanFixture.setUp(MockedSessionBeanFixture.java:89)
at junit.framework.TestCase.runBare(TestCase.java:128)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:120)
at junit.framework.TestSuite.runTest(TestSuite.java:230)
at junit.framework.TestSuite.run(TestSuite.java:225)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:79)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!

I am also with this problem. Have you figured out how to solve it?

In fact, if you use the same test code with the version 1.1 of EJB3Unit, it runs (at least on my case)... but with the newest version (2.0-RC), there are problems with Hibernate.

Other issue that i found with EJB3Unit was that the EntityManager does not REALLY works. EJB3Unit pretends that he executes the EntityManager.persist() but if you try to use a query to find your object after, it does not exist (and if you use the method persist from the class PoJoFixture then the object will be really persisted), at least this happened on the test that i have executed. Anyone knows how to solve this other problem?

Thanks!!!


My code that works with version 1.1 but not with 2.0:
package test.family.test;

import test.family.dto.Man;
import test.family.dto.persistence.ChildBean;
import test.family.dto.persistence.ManBean;
import test.family.dto.persistence.ManFactory;
import test.family.dto.persistence.PersonBean;
import test.family.dto.persistence.WomanBean;
import test.family.service.business.ManBusiness;

import com.bm.creators.SessionBeanFactory;
import com.bm.testsuite.BaseSessionBeanFixture;

public class ManBusinessTestEjb3Unit extends
BaseSessionBeanFixture<ManBusiness> {

private static final Class[] usedBeans = { PersonBean.class, ManBean.class, WomanBean.class, ChildBean.class };


public ManBusinessTestEjb3Unit() {
super(ManBusiness.class, usedBeans);
}

public void testDependencyInjection() {
final ManBusiness manBusiness = this.getBeanToTest();
assertNotNull(manBusiness);
}

public void testCreateMan() {
final ManBusiness manBusiness = this.getBeanToTest();
Man m1 = ManFactory.create();
m1.setName("m1");
System.out.println("ID" + m1.getId());
m1.setId(10L);
System.out.println("ID" + m1.getId());
Man mTest = manBusiness.create(m1);
assertNotNull(mTest);
assertEquals("Man name", m1.getName(), mTest.getName());
Man mTest2 = manBusiness.findByPK(m1);
assertNotNull(mTest2); //FAILS -> entityManager does not work!
//assertEquals("Man name", m1.getName(), mTest2.getName());
}
}
 
chandrasekaran mohanlal
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Cause for the Exception is ejb3unit-2.0.0-RC-1.jar file. Plase try to download the snapshot version (ejb3unit-2.0.0-SNAPSHOT.jar) file to rectify the problem.

Please let me know if you resolve your another problem.

Thanks,
Chandrasekar Mohanlal

 
Marcelo Zambiasi
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much!!! I forgot completely the snapshot version...

About the other problem, i think it's almost solved (i will test more Monday and can post the result after).

You have to use a commit transaction after every EntityManager.persist() . But i'm still having some problems with finding the object after...

Example of how persists...


Monday i will have more time... and i will post here again.
 
Marcelo Zambiasi
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After doing some tests, I figured out that the persist really works. You have to use transactions... .begin(); and after .commit() .

Other problem that i found, it is that when running many tests, the database was not all cleaned after each test (like the standard EntityBean test from EJB3Unit). So, a method of this type may be useful before executing your tests:

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

chandrasekaran mohanlal wrote:Hi,

Cause for the Exception is ejb3unit-2.0.0-RC-1.jar file. Plase try to download the snapshot version (ejb3unit-2.0.0-SNAPSHOT.jar) file to rectify the problem.

Please let me know if you resolve your another problem.

Thanks,
Chandrasekar Mohanlal



Is it the snapshot version published into maven dated of the 26-Aug-2008 ?
With it, I always have this error.

The only thing about this jar is that we have deleted jboss packages and some javax because of conflicts with our project versions.
 
Marcelo Zambiasi
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Thomas Fra wrote:

chandrasekaran mohanlal wrote:Hi,

Cause for the Exception is ejb3unit-2.0.0-RC-1.jar file. Plase try to download the snapshot version (ejb3unit-2.0.0-SNAPSHOT.jar) file to rectify the problem.

Please let me know if you resolve your another problem.

Thanks,
Chandrasekar Mohanlal



Is it the snapshot version published into maven dated of the 26-Aug-2008 ?
With it, I always have this error.

The only thing about this jar is that we have deleted jboss packages and some javax because of conflicts with our project versions.



At least with me, the problem was solved dowloading the snapshot version (this from 26-08-2008).

If you are using Maven:
<dependency>
<groupId>com.bm</groupId>
<artifactId>ejb3unit</artifactId>
<version>2.0.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
And:
<repository>
<id>ejb3unit</id>
<name>Wicket repository</name>
<!--<url>http://ejb3unit.sourceforge.net/maven2</url>; For not snapshot versions -->
<url>http://ejb3unit.sourceforge.net/maven2-snap</url>;
</repository>
 
Thomas Fra
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I retry with the last snapshot au august 2008, and I always has the problem. but my problem is not completely the same. the line on the exception is 37 and not 36
java.lang.ClassCastException: org.ejb3unit.asm.jar.Type
at com.bm.ejb3metadata.annotations.analyzer.JavaxInterceptorInterceptorsVisitor.visitEnd(JavaxInterceptorInterceptorsVisitor.java:37)
at org.ejb3unit.asm.jar.ClassReader.a(Unknown Source)
at org.ejb3unit.asm.jar.ClassReader.a(Unknown Source)
at org.ejb3unit.asm.jar.ClassReader.a(Unknown Source)
at org.ejb3unit.asm.jar.ClassReader.accept(Unknown Source)
at org.ejb3unit.asm.jar.ClassReader.accept(Unknown Source)
at com.bm.ejb3metadata.MetadataAnalyzer.read(MetadataAnalyzer.java:113)
at com.bm.ejb3metadata.MetadataAnalyzer.analyze(MetadataAnalyzer.java:79)
at com.bm.ejb3metadata.MetadataAnalyzer.analyzeClasses(MetadataAnalyzer.java:49)
at com.bm.ejb3metadata.MetadataAnalyzer.initialize(MetadataAnalyzer.java:36)
at com.bm.ejb3metadata.annotations.metadata.MetaDataCache.getMetaData(MetaDataCache.java:128)
at com.bm.ejb3metadata.annotations.metadata.MetaDataCache.getMockModuleCreator(MetaDataCache.java:152)
at com.bm.testsuite.mocked.MockedSessionBeanFixture.setUp(MockedSessionBeanFixture.java:89)
at com.bm.testsuite.junit4.MockedSessionBeanJUnit4Fixture.setUp(MockedSessionBeanJUnit4Fixture.java:69)
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.junit.internal.runners.MethodRoadie.runBefores(MethodRoadie.java:122)
at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:86)
at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
at org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)
at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
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:165)
at org.apache.maven.surefire.Surefire.run(Surefire.java:107)
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:289)
at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:993)

And I am on a MockedSessionBeanJUnit4Fixture.
 
Thomas Fra
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think I am seeing the difference between our 2 cases, you were with a @Remote annotation and me with an @Interceptors annotation.
There is a visitor for Remote into package com.bm.ejb3metadata.annotations.analyzer.classes but none for Interceptor.
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Marcelo,

How you managed to get the thing working. I mean in-memory is working like charm. But I want to connect my existing test schema. Its giving me ClassCastException on hibernate Dialect. See below..



I am using the correct version of Hibernate, I suppose. As given on the website, hibernate-core 3.3.0.SP1 and SNAPSHOT of EJB3Unit. How about you?
 
reply
    Bookmark Topic Watch Topic
  • New Topic