I'm not sure if this is a bug in GlassFish 4 or some kind of misconfiguration but to use a datasource in this way you have to define a resource reference either in your web.xml
or in a context.xml
.
The web.xml
entry should look similar to this:
<resource-ref>
<res-ref-name>jdbc/music</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
Make sure you haven set up the correct res-type
for your configured datasource. If you already have something like this (I suppose because if I remove this entry I get a different error) or if this doesn't fix the problem you may have to set up the resource reference in glassfish-web.xml
too.
It should look similar to this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app error-url="">
<class-loader delegate="true"/>
<resource-ref>
<res-ref-name>jdbc/music</res-ref-name>
<jndi-name>jdbc/music</jndi-name>
</resource-ref>
</glassfish-web-app>
See also: