Attached are the descriptor files that you asked for.


Regards
Surendra
----- Original Message -----
From: Hélène JOANIN <[EMAIL PROTECTED]>
To: Surendra <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Wednesday, April 18, 2001 4:27 PM
Subject: Re: Database connection in CMP


> Hi,
>
> Could you, please, send us the two XML deployment descriptor files
> (standard and JOnAS specific) ?
> This will probably help us to understand the problem.
>
> Kind regards.
> Hélène.
>
> > Surendra wrote:
> >
> > Hi,
> >
> >
> > I want to execute a query in CMP(my requirement). I wrote following
> > method
> >
> > private DataSource dataSource = null;
> > private Connection getConnection() throws EJBException, SQLException {
> >
> >    if (dataSource == null) {
> >       file://Finds DataSource from JNDI
> >       Context   initialContext = null;
> >       try {
> >         initialContext = new InitialContext();
> >         dataSource =
> > (DataSource)initialContext.lookup("java:comp/env/jdbc/StudentID");
> >       } catch (Exception e) {
> >         System.out.println("Cannot lookup dataSource " + e);
> >         throw new javax.ejb.EJBException("Cannot lookup dataSource ");
> >       }
> >   }
> >   return dataSource.getConnection();
> > }
> >
> > But while executing the method i am getting following error Can you
> > please tell me what is the reson.
> >
> > Error
> > java.lang.ClassCastException: student.JOnASStuBeanHome
> >         at student.StudentBean.getConnection(StudentBean.java:59)
> >         at student.StudentBean.getStudent(StudentBean.java:79)
> >         at student.StudentBean.ejbCreate(StudentBean.java:39)
> >         at
> > student.JOnASStuBeanBean.ejbCreate(JOnASStuBeanBean.java:60)
> >         at student.JOnASStuBeanHome.create(JOnASStuBeanHome.java:113)
> >         at
> > student.JOnASStuBeanHome_Skel.send(JOnASStuBeanHome_Skel.java:40)
> >         at
> > org.objectweb.david.libs.protocols.giop.GIOPProtocol$ServerSession_Lo
> > w.send(GIOPProtocol.java:621)
> >         at
> > org.objectweb.jonathan.libs.protocols.tcpip.TcpIpProtocol$Session.run
> > (TcpIpProtocol.java:396)
> >         at
> > org.objectweb.jonathan.libs.resources.JScheduler$JJob.run(JScheduler.
> > java:265)
> >  System exc. => Rollback the transaction.
> >  JEntityHome.removeEJBObject: pk = null
> >  postinvoke: System Exception in a home method:javax.ejb.EJBException:
> > Cannot lo
> > okup dataSource
> >
> > Regards
> > Surendra
>
> --
> -=- Hélène JOANIN -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
>   mailto:[EMAIL PROTECTED]   http://www.evidian.com
>   Phone: 33.4.76.29.73.53            Fax: 33.4.76.29.76.00
>   Download our EJB Server JOnAS at http://www.objectweb.org
>
<?xml version="1.0"?>
<jonas-ejb-jar>
    <jonas-entity>
        <ejb-name>StuBean</ejb-name>
        <jndi-name>StuHome</jndi-name>
        <jonas-resource>
            <res-ref-name>jdbc/StudentID</res-ref-name>
            <jndi-name>jdbc_3</jndi-name>
        </jonas-resource>
        <jdbc-mapping>
            <jndi-name>jdbc_3</jndi-name>
            <jdbc-table-name>students</jdbc-table-name>
            <cmp-field-jdbc-mapping>
                <field-name>id</field-name>
                <jdbc-field-name>id</jdbc-field-name>
            </cmp-field-jdbc-mapping>
            <cmp-field-jdbc-mapping>
                <field-name>lastName</field-name>
                <jdbc-field-name>lastName</jdbc-field-name>
            </cmp-field-jdbc-mapping>
            <cmp-field-jdbc-mapping>
                <field-name>firstName</field-name>
                <jdbc-field-name>firstName</jdbc-field-name>
            </cmp-field-jdbc-mapping>
            <cmp-field-jdbc-mapping>
                <field-name>company</field-name>
                <jdbc-field-name>company</jdbc-field-name>
            </cmp-field-jdbc-mapping>
            <cmp-field-jdbc-mapping>
                <field-name>email</field-name>
                <jdbc-field-name>email</jdbc-field-name>
            </cmp-field-jdbc-mapping>
            <cmp-field-jdbc-mapping>
                <field-name>courseTitle</field-name>
                <jdbc-field-name>courseTitle</jdbc-field-name>
            </cmp-field-jdbc-mapping>
            <cmp-field-jdbc-mapping>
                <field-name>courseLocation</field-name>
                <jdbc-field-name>courseLocation</jdbc-field-name>
            </cmp-field-jdbc-mapping>
            <cmp-field-jdbc-mapping>
                <field-name>courseExpectations</field-name>
                <jdbc-field-name>courseExpectations</jdbc-field-name>
            </cmp-field-jdbc-mapping>
            <cmp-field-jdbc-mapping>
                <field-name>courseStartDate</field-name>
                <jdbc-field-name>courseStartDate</jdbc-field-name>
            </cmp-field-jdbc-mapping>
            <finder-method-jdbc-mapping>
                <jonas-method>
                    <method-name>findByNumber</method-name>
                </jonas-method>
                <jdbc-where-clause>where id = ?</jdbc-where-clause>
            </finder-method-jdbc-mapping>
            <finder-method-jdbc-mapping>
                <jonas-method>
                    <method-name>findAllStudents</method-name>
                </jonas-method>
                <jdbc-where-clause></jdbc-where-clause>
            </finder-method-jdbc-mapping>
        </jdbc-mapping>
    </jonas-entity>
</jonas-ejb-jar>
<?xml version="1.0"?>
<ejb-jar>
    <enterprise-beans>
        <entity>
            <ejb-name>StuBean</ejb-name>
            <home>student.StudentHome</home>
            <remote>student.StudentRemote</remote>
            <ejb-class>student.StudentBean</ejb-class>
            <persistence-type>Container</persistence-type>
            <prim-key-class>student.StudentBeanPK</prim-key-class>
            <reentrant>False</reentrant>
            <cmp-field>
                <field-name>id</field-name>
            </cmp-field>
            <cmp-field>
                <field-name>lastName</field-name>
            </cmp-field>
            <cmp-field>
                <field-name>firstName</field-name>
            </cmp-field>
            <cmp-field>
                <field-name>company</field-name>
            </cmp-field>
            <cmp-field>
                <field-name>email</field-name>
            </cmp-field>
            <cmp-field>
                <field-name>courseTitle</field-name>
            </cmp-field>
            <cmp-field>
                <field-name>courseLocation</field-name>
            </cmp-field>
            <cmp-field>
                <field-name>courseExpectations</field-name>
            </cmp-field>
            <cmp-field>
                <field-name>courseStartDate</field-name>
            </cmp-field>
            <resource-ref>
                <res-ref-name>jdbc/StudentID</res-ref-name>
                <res-type>javax.sql.DataSource</res-type>
                <res-auth>Container</res-auth>
            </resource-ref>
        </entity>
    </enterprise-beans>
    <assembly-descriptor>
        <container-transaction>
            <method>
                <ejb-name>StuBean</ejb-name>
                <method-name>*</method-name>
            </method>
            <trans-attribute>Required</trans-attribute>
        </container-transaction>
    </assembly-descriptor>
</ejb-jar>

Reply via email to