You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@geronimo.apache.org by Olivier Voutat <ol...@gmail.com> on 2006/03/17 21:12:05 UTC
Help with CMP Entity Bean
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
Re: Help with CMP Entity Bean
Posted by Gianny Damour <gi...@optusnet.com.au>.
Hello Aaron,
Dohh - After review of RefContext.getConnectionFactoryContainerId I
confirm that I was definitively wrong. Sorry for having provided such a
wrong response and I hope that I did not confuse too many users :(
Gianny
Aaron Mulder wrote:
>Gianny -- I don't believe your resource-link information is correct.
>A resource-link should work for either a resource (in this case, DB
>pool) deployed in the same EAR, *or* in the top level of the server
>(e.g. as a standalone database connection pool). Do you disagree?
>(My understanding from David J is that ejb-link, in contrast, works
>the way you describe, so the two are not similar in that respect.)
>
>Thanks,
> Aaron
>
>On 3/18/06, Gianny Damour <gi...@optusnet.com.au> wrote:
>
>
>>Olivier Voutat wrote:
>>
>>
>>
>>>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
>>><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>
>>>http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd">
>>> <display-name>ProdutoCmp</display-name>
>>> <enterprise-beans>
>>>
>>>
>><...>
>>
>>
>>
>>><?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>
>>>
>>>
>>If the database pool is already deployed, i.e. not deployed at the same
>>time than your EJB module within an EAR, then you cannot use the
>>resource-link tag. This tag allows you to point to a
>>connectiondefinition-instance defined in the same EAR module than your
>>EJB moduler (this is more or less like the ejb-link mechanism).
>>
>>In your case, you need to use a
>>http://geronimo.apache.org/xml/ns/naming-1.0:objectNameGroup (have a
>>look to geronimo-naming-1.0.xsd for more details). I think that you want
>>something like this:
>> <cmp-connection-factory>
>> <application><the name of the EAR module defining the RAR - null
>>if the RAR was deployed as a standalone module></application>
>> <module><name of the RAR module></module>
>> <name><name of the connectiondefinition-instance>.</name>
>> </cmp-connection-factory>
>>
>>Thanks,
>>Gianny
>>
>>
>>
>>
>
>
>
>
Re: Help with CMP Entity Bean
Posted by Aaron Mulder <am...@alumni.princeton.edu>.
Gianny -- I don't believe your resource-link information is correct.
A resource-link should work for either a resource (in this case, DB
pool) deployed in the same EAR, *or* in the top level of the server
(e.g. as a standalone database connection pool). Do you disagree?
(My understanding from David J is that ejb-link, in contrast, works
the way you describe, so the two are not similar in that respect.)
Thanks,
Aaron
On 3/18/06, Gianny Damour <gi...@optusnet.com.au> wrote:
> Olivier Voutat wrote:
>
> > 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
> > <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>
> > http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd">
> > <display-name>ProdutoCmp</display-name>
> > <enterprise-beans>
>
> <...>
>
> > <?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>
>
> If the database pool is already deployed, i.e. not deployed at the same
> time than your EJB module within an EAR, then you cannot use the
> resource-link tag. This tag allows you to point to a
> connectiondefinition-instance defined in the same EAR module than your
> EJB moduler (this is more or less like the ejb-link mechanism).
>
> In your case, you need to use a
> http://geronimo.apache.org/xml/ns/naming-1.0:objectNameGroup (have a
> look to geronimo-naming-1.0.xsd for more details). I think that you want
> something like this:
> <cmp-connection-factory>
> <application><the name of the EAR module defining the RAR - null
> if the RAR was deployed as a standalone module></application>
> <module><name of the RAR module></module>
> <name><name of the connectiondefinition-instance>.</name>
> </cmp-connection-factory>
>
> Thanks,
> Gianny
>
>
Re: Help with CMP Entity Bean
Posted by Olivier Voutat <ol...@gmail.com>.
Thanks for your time Gianny but I already got it looking to an example that
Aaron teached me before.
Best Regards,
Olivier
On 3/18/06, Gianny Damour <gi...@optusnet.com.au> wrote:
>
> Olivier Voutat wrote:
>
> > 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
> > <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>
> > http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd">
> > <display-name>ProdutoCmp</display-name>
> > <enterprise-beans>
>
> <...>
>
> > <?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>
>
> If the database pool is already deployed, i.e. not deployed at the same
> time than your EJB module within an EAR, then you cannot use the
> resource-link tag. This tag allows you to point to a
> connectiondefinition-instance defined in the same EAR module than your
> EJB moduler (this is more or less like the ejb-link mechanism).
>
> In your case, you need to use a
> http://geronimo.apache.org/xml/ns/naming-1.0:objectNameGroup (have a
> look to geronimo-naming-1.0.xsd for more details). I think that you want
> something like this:
> <cmp-connection-factory>
> <application><the name of the EAR module defining the RAR - null
> if the RAR was deployed as a standalone module></application>
> <module><name of the RAR module></module>
> <name><name of the connectiondefinition-instance>.</name>
> </cmp-connection-factory>
>
> Thanks,
> Gianny
>
>
--
Olivier & Cidiane Voutat
Rua Praia de Muriú, 9188
Cep 59092-390 / Natal - RN
Tel: (84) 3219-0427 Cel: (84) 9977-3917
Re: Help with CMP Entity Bean
Posted by Gianny Damour <gi...@optusnet.com.au>.
Olivier Voutat wrote:
> 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
> <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>
> http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd">
> <display-name>ProdutoCmp</display-name>
> <enterprise-beans>
<...>
> <?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>
If the database pool is already deployed, i.e. not deployed at the same
time than your EJB module within an EAR, then you cannot use the
resource-link tag. This tag allows you to point to a
connectiondefinition-instance defined in the same EAR module than your
EJB moduler (this is more or less like the ejb-link mechanism).
In your case, you need to use a
http://geronimo.apache.org/xml/ns/naming-1.0:objectNameGroup (have a
look to geronimo-naming-1.0.xsd for more details). I think that you want
something like this:
<cmp-connection-factory>
<application><the name of the EAR module defining the RAR - null
if the RAR was deployed as a standalone module></application>
<module><name of the RAR module></module>
<name><name of the connectiondefinition-instance>.</name>
</cmp-connection-factory>
Thanks,
Gianny