You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Alexander von Hedenström <he...@googlemail.com> on 2008/04/22 13:49:31 UTC

BMP with OpenEJB standalone + Tomcat 6

Hi!

I'm trying to build and deploy a small entity bean with OpenEJB. Now there
is some trouble receiving a DataSource. What I did so far: I configured the
data source in openejb.xml (as Connector and Recource), added a resource-ref
to ejb-jar.xml, and tried to fetch it via JNDI. I varied this very often,
searching through the list and web for hints, with no success. If I browse
the context, I find my beans but no data source object or any other
resource.

How do I get my data source into the context?

I have no persistence.xml, since I don't use CMP. Is that correct, or what
must it contain for BMP?

I have no openejb-jar.xml either. It is neccessary? Session beans works
fine. What to put there?

Thank you for your help!
Alexander

Re: BMP with OpenEJB standalone + Tomcat 6

Posted by Dain Sundstrom <da...@iq80.com>.
Alexander is not subscribed to this list so I'm CCing him directly.

-dain

On Apr 22, 2008, at 11:11 AM, David Blevins wrote:
> On Apr 22, 2008, at 4:49 AM, Alexander von Hedenström wrote:
>
>> Hi!
>>
>> I'm trying to build and deploy a small entity bean with OpenEJB.  
>> Now there
>> is some trouble receiving a DataSource. What I did so far: I  
>> configured the
>> data source in openejb.xml (as Connector and Recource), added a  
>> resource-ref
>> to ejb-jar.xml, and tried to fetch it via JNDI. I varied this very  
>> often,
>> searching through the list and web for hints, with no success. If I  
>> browse
>> the context, I find my beans but no data source object or any other
>> resource.
>>
>> How do I get my data source into the context?
>>
>> I have no persistence.xml, since I don't use CMP. Is that correct,  
>> or what
>> must it contain for BMP?
>>
>> I have no openejb-jar.xml either. It is neccessary? Session beans  
>> works
>> fine. What to put there?
>
> Hi Alexander,
>
> If you can post some information from your openejb.log, the resource- 
> ref declaration, and the jndi name you're looking up we can take a  
> look.
>
> You shouldn't need an openejb-jar.xml if you gave your openejb.xml  
> <Resource> and ejb-jar.xml <resource-ref> the same name (or even if  
> they end in the same name).  For example, this should work  
> automatically:
>
> --openejb.xml--
> <openejb>
>  <Resource id="Orange" type="DataSource">
>  ...
>  </Resource>
> </openejb>
> ---------------
>
> --ejb-jar.xml--
> <ejb-jar>
>  ...
>      <resource-ref>
>        <res-ref-name>jdbc/Orange</res-ref-name>
>        <res-type>javax.sql.DataSource</res-type>
>        <res-auth>Container</res-auth>
>      </resource-ref>
>  ...
> </ejb-jar>
> ---------------
>
> Technically, we'll look for a Resource with id "jdbc/Orange" first,  
> but not finding that we'll scrape off the prefix and look for a  
> Resource with "Orange" as the id. With the above ref you should be  
> able to look up the datasource in the bean that declared it as  
> follows:
>
> InitialContext context = new InitialContext();
> DataSource dataSource = (DataSource) context.lookup("java:comp/env/ 
> jdbc/Orange");
>
>
> With the above setup you should see something like this in the log:
>
>  INFO - Configuring Service(id=Orange, type=Resource, provider- 
> id=Default JDBC Database)
>  ...
>  INFO - Auto-linking resource-ref 'jdbc/Orange' in bean YourBmpBean  
> to Resource(id=Orange)
>
> Hope this helps!
>
> -David
>
>


Re: BMP with OpenEJB standalone + Tomcat 6

Posted by David Blevins <da...@visi.com>.
On Apr 23, 2008, at 12:37 AM, Alexander von Hedenström wrote:

> Hi!
>
> Thank you, this helped me a lot. The problem was this:
>
> 2008/4/22 David Blevins <da...@visi.com>:
>
>> Technically, we'll look for a Resource with id "jdbc/Orange" first,  
>> but
>> not finding that we'll scrape off the prefix and look for a  
>> Resource with
>> "Orange" as the id. With the above ref you should be able to look  
>> up the
>> datasource in the bean that declared it as follows:
>>
>> InitialContext context = new InitialContext();
>> DataSource dataSource = (DataSource)
>> context.lookup("java:comp/env/jdbc/Orange");
>>
>
> I just looked in the wrong context. In my test servlet however, I  
> found the
> home object of my EJB by asking for:
>
> Properties p = *new* Properties();
> p.put("java.naming.factory.initial",
> "org.openejb.client.RemoteInitialContextFactory");
> javax.naming.InitialContext ctx = *new*  
> javax.naming.InitialContext(p);
> Object obj = ctx.lookup("/MyRemoteHome");
>
> No java:comp/env here! This works on the servlet side to find the  
> bean, but
> not for the bean itself to find the data source.

Hehe.  That would be an issue, yes :)

Just as a note, if you're using Tomcat and OpenEJB together via the  
openejb.war file, you can use Java EE 5 annotations in your Servlets  
to reference your EJBs.

At simplest in your Servlet you can do:

   @EJB private MyBeanInterface myBean;

If you have more than one bean with "MyBeanInterface", then you can:

   @EJB(beanName="theEjbNameOfYourBean")
   private MyBeanInterface myBean;

-David


Re: BMP with OpenEJB standalone + Tomcat 6

Posted by Alexander von Hedenström <he...@googlemail.com>.
Hi!

Thank you, this helped me a lot. The problem was this:

2008/4/22 David Blevins <da...@visi.com>:

>  Technically, we'll look for a Resource with id "jdbc/Orange" first, but
> not finding that we'll scrape off the prefix and look for a Resource with
> "Orange" as the id. With the above ref you should be able to look up the
> datasource in the bean that declared it as follows:
>
>  InitialContext context = new InitialContext();
>  DataSource dataSource = (DataSource)
> context.lookup("java:comp/env/jdbc/Orange");
>

I just looked in the wrong context. In my test servlet however, I found the
home object of my EJB by asking for:

Properties p = *new* Properties();
p.put("java.naming.factory.initial",
"org.openejb.client.RemoteInitialContextFactory");
javax.naming.InitialContext ctx = *new* javax.naming.InitialContext(p);
Object obj = ctx.lookup("/MyRemoteHome");

No java:comp/env here! This works on the servlet side to find the bean, but
not for the bean itself to find the data source.

Thanks again,

Alexander

Re: BMP with OpenEJB standalone + Tomcat 6

Posted by David Blevins <da...@visi.com>.
On Apr 22, 2008, at 4:49 AM, Alexander von Hedenström wrote:

> Hi!
>
> I'm trying to build and deploy a small entity bean with OpenEJB. Now  
> there
> is some trouble receiving a DataSource. What I did so far: I  
> configured the
> data source in openejb.xml (as Connector and Recource), added a  
> resource-ref
> to ejb-jar.xml, and tried to fetch it via JNDI. I varied this very  
> often,
> searching through the list and web for hints, with no success. If I  
> browse
> the context, I find my beans but no data source object or any other
> resource.
>
> How do I get my data source into the context?
>
> I have no persistence.xml, since I don't use CMP. Is that correct,  
> or what
> must it contain for BMP?
>
> I have no openejb-jar.xml either. It is neccessary? Session beans  
> works
> fine. What to put there?

Hi Alexander,

If you can post some information from your openejb.log, the resource- 
ref declaration, and the jndi name you're looking up we can take a look.

You shouldn't need an openejb-jar.xml if you gave your openejb.xml  
<Resource> and ejb-jar.xml <resource-ref> the same name (or even if  
they end in the same name).  For example, this should work  
automatically:

--openejb.xml--
<openejb>
   <Resource id="Orange" type="DataSource">
   ...
   </Resource>
</openejb>
---------------

--ejb-jar.xml--
<ejb-jar>
   ...
       <resource-ref>
         <res-ref-name>jdbc/Orange</res-ref-name>
         <res-type>javax.sql.DataSource</res-type>
         <res-auth>Container</res-auth>
       </resource-ref>
   ...
</ejb-jar>
---------------

Technically, we'll look for a Resource with id "jdbc/Orange" first,  
but not finding that we'll scrape off the prefix and look for a  
Resource with "Orange" as the id. With the above ref you should be  
able to look up the datasource in the bean that declared it as follows:

  InitialContext context = new InitialContext();
  DataSource dataSource = (DataSource) context.lookup("java:comp/env/ 
jdbc/Orange");


With the above setup you should see something like this in the log:

   INFO - Configuring Service(id=Orange, type=Resource, provider- 
id=Default JDBC Database)
   ...
   INFO - Auto-linking resource-ref 'jdbc/Orange' in bean YourBmpBean  
to Resource(id=Orange)

Hope this helps!

-David