This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 134983 - lookup DataSource generated code doesn't work
Summary: lookup DataSource generated code doesn't work
Status: RESOLVED WONTFIX
Alias: None
Product: javaee
Classification: Unclassified
Component: EJB (show other bugs)
Version: 6.x
Hardware: All All
: P3 blocker (vote)
Assignee: Martin Fousek
URL:
Keywords:
Depends on: 143603
Blocks:
  Show dependency tree
 
Reported: 2008-05-13 18:45 UTC by jrcampins
Modified: 2011-10-10 18:05 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description jrcampins 2008-05-13 18:45:08 UTC
I have created an Enterprise Application project using NetBeans. The project contains several EJB modules, J2SE
libraries, Web Applications, etc.

In a standard java class within one of my EJB modules I used right click + “Enterprise Resources” + “Use Database” to
generate the corresponding lookup code.

The generated code was:

private DataSource getJdbcPublic_PostgreSQL() throws NamingException {
    Context c = new InitialContext();
    return (DataSource) c.lookup("java:comp/env/jdbc/public_PostgreSQL");
}

To make it work, I had to check the “Copy Selected Data Source To Project” option at the “Add Data Source Reference”
window and then change the generated code. Specifically I had to remove the “java:comp/env/” prefix from the resource
name used in the return statement.

I have a very similar problem trying to call a Session Bean. I will open another issue for that.
Comment 1 Martin Fousek 2011-10-10 18:05:33 UTC
Actually "java:comp/env/jdbc/public_PostgreSQL" is the correct JNDI name for getting DataSource in EAR. "jdbc/public_PostgreSQL" worked to you because you GlassFish can work and works in that way for resources inside itself. 

Take a look onto naming policy:
http://download.oracle.com/javase/jndi/tutorial/beyond/misc/policy.html

Or this is really great blog post with cases where java:comp/env/ should be omitted. See point 6 and 7 - they match to your troubles:
http://javahowto.blogspot.com/2006/07/when-and-where-not-to-use-javacompenv.html

Closing as wontfix since the code is generated correctly according to naming convention and specification.