Note that there are some explanatory texts on larger screens.

plurals
  1. POjava.lang.ClassCastException: $Proxy96 cannot be cast to ticket.app.DatesFacade
    primarykey
    data
    text
    <p>I am entering some code into a Hudson Server run on a Ubuntu box in order to run some Code Metrics(Sonar) and Cobertura on the code. The project runs off of Glassfish3.1, uses Maven3, written in Java, JSF 2.0 and uses OracleXE Database(irrelevant).</p> <p>The error is being thrown when trying to create an instance of an Facade inside of my JUnit tests. The tests run fine when I am running them from Netbeans, but when Hudson does the automatic build on it I get this error:</p> <pre><code> java.lang.ClassCastException: $Proxy96 cannot be cast to ticket.app.DatesFacade at ticket.app.EventsControllerTest.setUp(EventsControllerTest.java:60) 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 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:616) at org.apache.maven.surefire.junit.JUnitTestSet.execute(JUnitTestSet.java:207) at org.apache.maven.surefire.junit.JUnit3Provider.executeTestSet(JUnit3Provider.java:107) at org.apache.maven.surefire.junit.JUnit3Provider.invoke(JUnit3Provider.java:79) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:616) at org.apache.maven.surefire.booter.ProviderFactory$ClassLoaderProxy.invoke(ProviderFactory.java:103) at $Proxy0.invoke(Unknown Source) at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:145) at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcess(SurefireStarter.java:87) at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:69) </code></pre> <p>The Hudson server is not run off of JBoss, it is run off of Tomcat. I add this detail because when I Google this error, I have found nothing but JBoss errors explaining that the facade is referenced in both the WAR and EAR files. </p> <p><strong>EDIT:</strong> This is how I am currently creating instances of the Facade (Which works fine when running the tests through Netbeans GF3.1):</p> <pre><code> Map properties = new HashMap(); properties.put(EJBContainer.MODULES, new File("target/classes")); properties.put("org.glassfish.ejb.embedded.glassfish.configuration.file", "server/config/domain.xml"); properties.put("oracle.jdbc.OracleDriver", "server/lib/ojdbc14.jar"); ejbContainer = EJBContainer.createEJBContainer(properties); ctx = ejbContainer.getContext(); EventsFacade instance = (EventsFacade)ctx.lookup("java:global/classes/EventsFacade"); </code></pre> <p><strong>EDIT:</strong> My EventsFacade:</p> <pre><code>@Stateful public class EventsFacade extends AbstractFacade&lt;Events&gt; { @PersistenceContext(unitName = "tickets_AppTicket_war_1.0-SNAPSHOTPU") private EntityManager em; protected EntityManager getEntityManager() { return em; } public EventsFacade() { super(Events.class); } } </code></pre> <p><strong>EDIT</strong>: And.. my AbstractFacade in full:</p> <pre><code>public abstract class AbstractFacade&lt;T&gt; { private Class&lt;T&gt; entityClass; public AbstractFacade(Class&lt;T&gt; entityClass) { this.entityClass = entityClass; } protected abstract EntityManager getEntityManager(); public void create(T entity) { getEntityManager().persist(entity); } public void edit(T entity) { getEntityManager().merge(entity); } public void remove(T entity) { getEntityManager().remove(getEntityManager().merge(entity)); } public T find(Object id) { return getEntityManager().find(entityClass, id); } public List&lt;T&gt; findAll() { javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery(); cq.select(cq.from(entityClass)); return getEntityManager().createQuery(cq).getResultList(); } public List&lt;T&gt; findRange(int[] range) { javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery(); cq.select(cq.from(entityClass)); javax.persistence.Query q = getEntityManager().createQuery(cq); q.setMaxResults(range[1] - range[0]); q.setFirstResult(range[0]); return q.getResultList(); } public int count() { javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery(); javax.persistence.criteria.Root&lt;T&gt; rt = cq.from(entityClass); cq.select(getEntityManager().getCriteriaBuilder().count(rt)); javax.persistence.Query q = getEntityManager().createQuery(cq); return ((Long) q.getSingleResult()).intValue(); } </code></pre> <p>}</p> <p><strong>EDIT:</strong> Created new Interface:</p> <pre><code> @Local public interface EventsInterface&lt;Events&gt; { int count(); void create(Events entity); void edit(Events entity); Events find(Object id); List&lt;Events&gt; findAll(); List&lt;Events&gt; findRange(int[] range); void remove(Events entity); } </code></pre> <p><strong>CHANGED:</strong> EventsFacade delaration:</p> <pre><code>public class EventsFacade extends AbstractFacade&lt;Events&gt; implements EventsInterface&lt;Events&gt; { </code></pre> <p><strong>EDIT:</strong> After getting the proxy error in my IDE after creating the new interface the output began to show:</p> <pre><code>Field Name == intfClass Field == interface ticket.app.EventsInterface Field Name == containerId Field == 85313541807800321 Field Name == delegate Field == com.sun.ejb.containers.EJBLocalObjectInvocationHandler@72b0f2b2 Field Name == isOptionalLocalBusinessView Field == false </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload