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.
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.
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.