Maven Embedded Glassfish Plugin - Datasource and JDBC Driver

I am trying to follow this approach to create a data source for embedded glass fish. The only significant difference between the tutorial and my code is that I start the server using the official maven plugin and the embedded-glassfish:run target.

There is a dependency in the pom file for the JDBC driver:

 <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> <version>1.3.155</version> </dependency> 

And my glassfish-resources.xml

 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd"> <resources> <jdbc-resource enabled="true" jndi-name="jdbc/myDatasource" object-type="user" pool-name="connectionPool"> <description/> </jdbc-resource> <jdbc-connection-pool datasource-classname="org.h2.jdbcx.JdbcDataSource" name="connectionPool" res-type="javax.sql.DataSource"> <property name="URL" value="jdbc:h2:~/Documents/Projetos/DBs/h2/glassfish/glassfish;AUTO_SERVER=TRUE;MVCC=TRUE"/> <property name="User" value="sa"/> <property name="Password" value=""/> <property name="driverClass" value="org.h2.Driver"/> </jdbc-connection-pool> </resources> 

It works fine using a local lake fish server. But no luck with the built-in instance:

06/03/2011 19:26:31 com.sun.enterprise.v3.server.ApplicationLifecycle deploy GRAVE: Invalid resource: JDBC / myDatasource_pm java.lang.RuntimeException: Invalid resource: jdbc / myDatasource_pm at com.sun.enterprise.connectors .ConnectorRuntime.lookupDataSourceInDAS (ConnectorRuntime.javaβˆ—39) in com.sun.enterprise.connectors.ConnectorRuntime.lookupPMResource (ConnectorRuntime.java:468) in org.glassfish.persistence.common.PersistenceHelper.lookupPMResel. Persistj org.glassfish.persistence.jpa.ProviderContainerContractInfoBase.lookupDataSource (ProviderContainerContractInfoBase.java:71) in

I don’t know ... Can anyone shed light on him?

+4
source share
2 answers

Figured it out. In the end, it had nothing to do with glassfish-resources.xml . The jdbc resource was correctly created and bound to java:app/jdbc/myDatasource .

My save unit (created by Netbeans) looked for jdbc/myDatasource and did not detect anything. I ended up changing the persistence block to point to the application namespace:

 <jta-data-source>java:app/jdbc/myDatasource</jta-data-source> 

Another option would be to use the embedded-glassfish:admin target to deploy a global resource with a non-standard name (so that I can use jdbc/myDatasource ). But standardization looked like the best approach.

This topic was very helpful.

+6
source

I still cannot work glassfish-resources.xml . But this pearl here seems to do the trick:

 @DataSourceDefinition(name = "java:app/jdbc/myDatasource", className = "org.h2.jdbcx.JdbcDataSource", url = "jdbc:h2:~/Documents/Projetos/DBs/h2/glassfish/glassfish;AUTO_SERVER=TRUE;MVCC=TRUE", user = "glassfish", password="emb" ) 

I created another user, because if the password is empty, there are some unpleasant exceptions. (Error?)

0
source

All Articles