geronimo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Olivier Voutat" <olivier.vou...@gmail.com>
Subject Help with CMP Entity Bean
Date Fri, 17 Mar 2006 20:12:05 GMT
Well,

I'm trying to create a simple application with a Cmp Entity Bean but I'm
missing how I should do the Database connection tags. My database pool is
already deployed and working. Here are my ejb-jar.xml and openejb-jar.xml:

<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar id="ejb-jar_ID" version="2.1" xmlns="
http://java.sun.com/xml/ns/j2ee" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd">
    <display-name>ProdutoCmp</display-name>
    <enterprise-beans>
    <entity>
        <ejb-name>Product</ejb-name>
        <home>br.cefetrn.cmp.ProductHome</home>
        <remote>br.cefetrn.cmp.Product</remote>
        <ejb-class>br.cefetrn.cmp.ProductBean</ejb-class>
        <persistence-type>Container</persistence-type>
        <prim-key-class>br.cefetrn.cmp.ProductPK</prim-key-class>
        <reentrant>false</reentrant>
        <cmp-version>2.x</cmp-version>
        <abstract-schema-name>PRODUCTS</abstract-schema-name>
        <cmp-field><field-name>productID</field-name></cmp-field>
        <cmp-field><field-name>name</field-name></cmp-field>
        <cmp-field><field-name>description</field-name></cmp-field>
        <cmp-field><field-name>basePrice</field-name></cmp-field>

        <!--  <primkey-field>productID</primkey-field> -->
        <query>
            <query-method>
                <method-name>findByName</method-name>
                <method-params>
                    <method-param>java.lang.String</method-param>
                </method-params>
            </query-method>
            <ejb-ql>
                SELECT DISTINCT OBJECT(p) FROM PRODUCTS p WHERE p.name = ?1
            </ejb-ql>
        </query>
        <query>
            <query-method>
                <method-name>findByDescription</method-name>
                <method-params>
                    <method-param>java.lang.String</method-param>
                </method-params>
            </query-method>
            <ejb-ql>
                SELECT DISTINCT OBJECT(p) FROM PRODUCTS p WHERE
p.description = ?1
            </ejb-ql>
        </query>
        <query>
            <query-method>
                <method-name>findByBasePrice</method-name>
                <method-params>
                    <method-param>double</method-param>
                </method-params>
            </query-method>
            <ejb-ql>
                SELECT DISTINCT OBJECT(p) FROM PRODUCTS p WHERE p.basePrice= ?1
            </ejb-ql>
        </query>
        <query>
            <query-method>
                <method-name>findExpensiveProducts</method-name>
                <method-params>
                    <method-param>double</method-param>
                </method-params>
            </query-method>
            <ejb-ql>
                <![CDATA[SELECT DISTINCT OBJECT(p) FROM PRODUCTS p WHERE
p.basePrice > ?1]]>
            </ejb-ql>
        </query>
        <query>
            <query-method>
                <method-name>findCheapProducts</method-name>
                <method-params>
                    <method-param>double</method-param>
                </method-params>
            </query-method>
            <ejb-ql>
                <![CDATA[SELECT DISTINCT OBJECT(p) FROM PRODUCTS p WHERE
p.basePrice < ?1]]>
            </ejb-ql>
        </query>
        <query>
            <query-method>
                <method-name>findAllProducts</method-name>
                <method-params>
                </method-params>
            </query-method>
            <ejb-ql>
                SELECT DISTINCT OBJECT(p) FROM PRODUCTS p WHERE
p.productIDIS NOT NULL
            </ejb-ql>
        </query>
    </entity>
    </enterprise-beans>
</ejb-jar>

<?xml version="1.0" encoding="UTF-8"?>
<openejb-jar xmlns="http://www.openejb.org/xml/ns/openejb-jar-2.0"
xmlns:nam="http://geronimo.apache.org/xml/ns/naming-1.0" xmlns:pkgen="
http://www.openejb.org/xml/ns/pkgen-2.0" xmlns:sec="
http://geronimo.apache.org/xml/ns/security-1.1" xmlns:sys="
http://geronimo.apache.org/xml/ns/deployment-1.0"
configId="ProdutoCmp/ProdutoCmp">
    <cmp-connection-factory>
        <resource-link>ProdutoCmp</resource-link>
    </cmp-connection-factory>
    <enterprise-beans>
    <entity>

         <ejb-name>Product</ejb-name>
        <jndi-name>Product</jndi-name>
        <local-jndi-name></local-jndi-name>
        <table-name>PRODUCTS</table-name>

        <cmp-field-mapping>
            <cmp-field-name>basePrice</cmp-field-name>
            <table-column>BASEPRICE</table-column>
        </cmp-field-mapping>
        <cmp-field-mapping>
            <cmp-field-name>productID</cmp-field-name>
            <table-column>PRODUCTID</table-column>
        </cmp-field-mapping>
        <cmp-field-mapping>
            <cmp-field-name>description</cmp-field-name>
            <table-column>DESCRIPTION</table-column>
        </cmp-field-mapping>
        <cmp-field-mapping>
            <cmp-field-name>name</cmp-field-name>
            <table-column>NAME</table-column>
        </cmp-field-mapping>
    </entity>
    </enterprise-beans>
</openejb-jar>

I'm pretty sure that's something very simple but after researching in the
online documentation, I'm still a little lost...

Thanks
--
Olivier & Cidiane Voutat
Rua Praia de Muriú, 9188
Cep 59092-390 / Natal - RN
Tel: (84) 3219-0427 Cel: (84) 9977-3917

Mime
View raw message