Site Navigation

Sep 13, 2010

javax.naming.NamingException: Lookup failed for 'jdbc/dbname' in SerialContext

Duke WavingWhile trying to deploy a Java EE6 Web application with NetBeans and Glassfish V3, the application deployment fails with the following error.

SEVERE: Exception while invoking class org.glassfish.persistence.jpa.JPADeployer prepare method java.lang.RuntimeException: javax.naming.NamingException: Lookup failed for 'jdbc/dbname' in SerialContext [Root exception is javax.naming.NameNotFoundException: dbname not found]

What does this mean? Basically, you have not defined the JDBC resource in the Web Application. In my case, neither the Database Connection Pool nor the JDBC resource had been defined. Once the persistence resources are defined, the application should deploy without any errors.

When first analyzing the problem, I thought, incorrectly, that since the persistence resources were defined in an included library, no definition was required in the Web application. This is not the case.

Update
A reader made a fair point that no pointers on how to create the JDBC resource or Connection Pool are included in this post. Here are the steps assuming you already have a Java EE project created. Right click your project and select the following menu options.
  • Connection Pool New -> Other -> Glassfish -> JDBC Connection Pool
  • JDBC Resource New -> Other -> Glassfish -> JDBC Resource
The wizard for each will walk you through the setup. Hope that helps.

2 comments:

Anonymous said...

How and where exactly have I to change / set these parameters? Thanks a lot

Tilman Hausherr said...

@1: Right-click on the project name, or in the menu + new, then "Glassfish", etc.

You can also do it in the admin console of glassfish,
http://localhost:4848

About the content of the parameters... google for them or look at the pages of your database vendor, e.g. here:
http://dev.mysql.com/doc/refman/5.0/en/connector-j-usagenotes-j2ee.html#connector-j-usagenotes-glassfish-config

Favorite Links Feed