persistence@glassfish.java.net

ClassCastException: SerialContext cannot be cast to javax.sql.DataSource

From: Eve Pokua <gorgeous65_at_msn.com>
Date: Sun, 3 Jan 2010 19:08:44 +0000

Hi,

 

I am trying to run an application which i get the following error-

 

[#|2010-01-03T18:52:56.606+0000|WARNING|sun-appserver2.1|javax.enterprise.system.stream.err|_ThreadID=22;_ThreadName=httpSSLWorkerThread-8080-0;_RequestID=53df71ea-b311-4a19-8b0d-16ddca64b5c5;|
java.lang.ClassCastException: com.sun.enterprise.naming.SerialContext cannot be cast to javax.sql.DataSource
 at oracle.toplink.essentials.jndi.JNDIConnector.connect(JNDIConnector.java:129)
 at oracle.toplink.essentials.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:184)
 at oracle.toplink.essentials.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:582)
 at oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:280)
 at oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:230)
 at oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:93)
 at oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:138)
 at oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:132)
 at oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:91)
 at com.mydomain.shoppingcart.dao.impl.ItemDaoImpl.list(ItemDaoImpl.java:23)
 at com.mydomain.shoppingcart.service.impl.ShoppingManager.findItems(ShoppingManager.java:40)
 at com.mydomain.shoppingcart.view.ShoppingViewHelper.findItems(ShoppingViewHelper.java:37)
 at com.mydomain.shoppingcart.view.Items.findItems(Items.java:37)
 at com.mydomain.shoppingcart.view.Items.getItems(Items.java:46)
 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 javax.el.BeanELResolver.getValue(BeanELResolver.java:293)
 at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:175)
 at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:64)
 at com.sun.el.parser.AstValue.getValue(AstValue.java:138)
 at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:206)
 at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
 at javax.faces.component.UIData.getValue(UIData.java:582)
 at javax.faces.component.UIData.getDataModel(UIData.java:1063)
 at javax.faces.component.UIData.setRowIndex(UIData.java:417)
 at com.sun.faces.renderkit.html_basic.TableRenderer.encodeBegin(TableRenderer.java:85)
 at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:788)
 at javax.faces.component.UIData.encodeBegin(UIData.java:879)
 at javax.faces.component.UIComponent.encodeAll(UIComponent.java:884)
 at javax.faces.render.Renderer.encodeChildren(Renderer.java:137)
 at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:812)
 at javax.faces.component.UIComponent.encodeAll(UIComponent.java:886)
 at javax.faces.component.UIComponent.encodeAll(UIComponent.java:892)
 at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592)
 at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:100)
 at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:176)
 at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
 at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
 at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
 at javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
 at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:427)
 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:315)
 at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:287)
 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:218)
 at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
 at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
 at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)
 at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:98)
 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:222)
 at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
 at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
 at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587)
 at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1096)
 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:166)
 at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
 at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
 at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587)
 at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1096)
 at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:288)
 at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:647)
 at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:579)
 at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:831)
 at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:341)
 at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:263)
 at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:214)
 at com.sun.enterprise.web.portunif.PortUnificationPipeline$PUTask.doTask(PortUnificationPipeline.java:380)
 at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265)
 at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)
|#]

 

 

Example of the code I am using -

 

@SuppressWarnings("unchecked")
 public List<Item> list() throws Exception {
  EntityManager em = null;
  EntityTransaction tx = null;
  try {
   em = JPAUtil.getEntityManagerFactory().createEntityManager();
   tx = em.getTransaction();
   tx.begin();
   return em.createQuery("select item from Item as item").getResultList();
  } catch (Exception e) {
   e.printStackTrace();
   throw e;
  } finally {
   if (tx != null) {
    tx.commit();
   }
   if (em != null && em.isOpen()) {
    em.close();
   }
  }
 }

 

and

 

public class JPAUtil {
 private static final EntityManagerFactory emf;
 static {
  try {
   emf = Persistence.createEntityManagerFactory("shopping-cart");
  } catch (Throwable ex) {
   System.err.println("Initial EntityManagerFactory creation failed." + ex);
   throw new ExceptionInInitializerError(ex);
  }
 }

 public static EntityManagerFactory getEntityManagerFactory() {
  return emf;
 }
}


 

This' a tutorial I am trying to get working -

 

http://monstersandwich.blogspot.com/2009/07/shopping-cart-web-application-part-7.html?showComment=1258103439449#c1405093771660150977

 

any ideas why I get the error -

 

I am also using this persistence

 

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
  <persistence-unit name="shopping-cart" transaction-type="JTA">
    <provider>oracle.toplink.essentials.PersistenceProvider</provider>
    <jta-data-source>jdbc_/shopping-cart2</jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
      <property name="toplink.ddl-generation" value="drop-and-create-tables"/>
    </properties>
  </persistence-unit>
</persistence>


 

Thanks

 

eve

 

 
                                               
_________________________________________________________________
Have more than one Hotmail account? Link them together to easily access both
 http://clk.atdmt.com/UKM/go/186394591/direct/01/