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


Reply via email to