Skip to main content

Glassfish v3 and mysql database access using Eclipse Galileo

12 replies [Last post]
drrevis
Offline
Joined: 2008-07-12

Hi,

I've been using MySQL with Glassfish v2ur2, and am in the process of trying to move to Glassfish v3. For now, I'm just trying to get a test app up and running to access the database, but no luck so far.

I'm using Glassfish Tools Bundle for Eclipse on a Mac running OSX 10.5.8. I have an EAR project that includes a JPA Project. In the JPA properties for this project, I have the platform set to EclipseLink 1.1.x and the User Library set to EclipseLink 1.1.2 - Galileo.

My persistence.xml file is:

<?xml version="1.0" encoding="UTF-8"?>

org.eclipse.persistence.jpa.PersistenceProvider
jdbc/testDB
com.leadingstep.test.db.User
true

I'm using mysql-connector-java-java-5.1.7-bin.jar, but I'm not quite sure where this is supposed to be. I have copies in:

~/workspace/libraries
~/workspace/.metadata/.plugins/com.sun.enterprise.jst.server.sunappsrv92/domain1/lib/ext

and I also specifically refer to the first copy in the java build path as an external jar.

Using the Data Source Explorer from Eclipse, I can access the database and see that it is there and set up with the correct column names, etc., but when I try to access it from the test app using the JPA Project, the injection of the EntityManager fails and I end up with a null EntityManager reference. I'm using:

@PersistenceContext(unitName="TestJPA")
private EntityManager em;

I wanted to turn on logging for JPA in Glassfish, but I don't see that in the available logger settings. Where does that get turned on? I turned on the logging for EclipseLink in the persistence.xml file and using that, I do see some errors generated when I try to use the JPA Tools from Eclipse to tell it to generate the tables from the entities. It gives me:

--------------------------------
Exception [EclipseLink-7060] (Eclipse Persistence Services - 2.0.0.v20091127-r5931)\
: org.eclipse.persistence.exceptions.ValidationException
Exception Description: Cannot acquire data source [jdbc/testDB].
Internal Exception: javax.naming.NamingException: Lookup failed for 'jdbc/testDB' i\
n SerialContext [Root exception is javax.naming.NamingException: Unable to acquire\
SerialContextProvider for SerialContext [Root exception is java.lang.NullPointerE\
xception]]
at org.eclipse.persistence.exceptions.ValidationException.cannotAcquireData\
Source(ValidationException.java:451)
at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.jav\
a:116)
at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.jav\
a:94)
at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(Dat\
asourceLogin.java:162)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDe\
tectDatasource(DatabaseSessionImpl.java:584)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(\
EntityManagerFactoryProvider.java:228)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(Entit\
yManagerSetupImpl.java:368)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerS\
ession(EntityManagerFactoryImpl.java:151)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEnti\
tyManagerImpl(EntityManagerFactoryImpl.java:207)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEnti\
tyManager(EntityManagerFactoryImpl.java:195)
at org.eclipse.jpt.eclipselink.core.ddlgen.Main.perform(Main.java:85)
at org.eclipse.jpt.eclipselink.core.ddlgen.Main.execute(Main.java:76)
at org.eclipse.jpt.eclipselink.core.ddlgen.Main.main(Main.java:63)
Caused by: javax.naming.NamingException: Lookup failed for 'jdbc/testDB' in SerialC\
ontext [Root exception is javax.naming.NamingException: Unable to acquire SerialCo\
ntextProvider for SerialContext [Root exception is java.lang.NullPointerException]\
]
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:4\
42)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:5\
69)
at javax.naming.InitialContext.lookup(InitialContext.java:396)
at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.jav\
a:110)
... 11 more
--------------------------------

I'm not sure how to figure out where the problem is from here. Does anyone know what the problem might be or can you help me to know where to look further to resolve this issue? I sure would appreciate it because I'm really stuck at this point.

Thanks for any help!

Renee

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
mvatkina
Offline
Joined: 2005-04-04

Is there an NPE in the log above the EclipseLink exception? Can you ping the datasource from the adminGUI?

drrevis
Offline
Joined: 2008-07-12

Yes, I can ping the datasource from the admin GUI with no problems. And no, there are no NPEs before the EclipseLink exception. The full error log is below.

Since I'm specifying the jta-data-source in the persistence.xml and not the individual properties, I don't know how to force it to use the javax.persistence.jdbc properties instead of the eclipselink.jdbc properties. Again, this error is generated when I use the JPA tools and tell it generate the tables from the entities. When I run the actual application, I don't get any error messages in server.log or the eclipse log, but the EntityManager reference doesn't get injected and is null.

[EL Info]: property eclipselink.jdbc.user is deprecated, property javax.persistence.jdbc.user should be used instead.
[EL Info]: property eclipselink.jdbc.driver is deprecated, property javax.persistence.jdbc.driver should be used instead.
[EL Info]: property eclipselink.jdbc.url is deprecated, property javax.persistence.jdbc.url should be used instead.
[EL Info]: property eclipselink.jdbc.password is deprecated, property javax.persistence.jdbc.password should be used instead.
[EL Config]: The access type for the persistent class [class com.leadingstep.test.db.School] is set to [FIELD].
[EL Config]: The access type for the persistent class [class com.leadingstep.test.db.User] is set to [FIELD].
[EL Config]: The alias name for the entity class [class com.leadingstep.test.db.School] is being defaulted to: School.
[EL Config]: The column name for element [field itemID] is being defaulted to: ITEMID.
[EL Config]: The column name for element [field schoolName] is being defaulted to: SCHOOLNAME.
[EL Config]: The alias name for the entity class [class com.leadingstep.test.db.User] is being defaulted to: User.
[EL Config]: The column name for element [field itemID] is being defaulted to: ITEMID.
[EL Config]: The column name for element [field userName] is being defaulted to: USERNAME.
[EL Info]: property eclipselink.jdbc.user is deprecated, property javax.persistence.jdbc.user should be used instead.
[EL Info]: property eclipselink.jdbc.driver is deprecated, property javax.persistence.jdbc.driver should be used instead.
[EL Info]: property eclipselink.jdbc.url is deprecated, property javax.persistence.jdbc.url should be used instead.
[EL Info]: property eclipselink.jdbc.password is deprecated, property javax.persistence.jdbc.password should be used instead.
[EL Info]: EclipseLink, version: Eclipse Persistence Services - 2.0.0.v20091127-r5931
[EL Severe]: Local Exception Stack:
Exception [EclipseLink-7060] (Eclipse Persistence Services - 2.0.0.v20091127-r5931): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Cannot acquire data source [jdbc/testDB].
Internal Exception: javax.naming.NamingException: Lookup failed for 'jdbc/testDB' in SerialContext [Root exception is javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext [Root exception is java.lang.NullPointerException]]
at org.eclipse.persistence.exceptions.ValidationException.cannotAcquireDataSource(ValidationException.java:451)
at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:116)
at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:94)
at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:162)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:584)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:228)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:368)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:151)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:207)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:195)
at org.eclipse.jpt.eclipselink.core.ddlgen.Main.perform(Main.java:85)
at org.eclipse.jpt.eclipselink.core.ddlgen.Main.execute(Main.java:76)
at org.eclipse.jpt.eclipselink.core.ddlgen.Main.main(Main.java:63)
Caused by: javax.naming.NamingException: Lookup failed for 'jdbc/testDB' in SerialContext [Root exception is javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext [Root exception is java.lang.NullPointerException]]
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:442)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:569)
at javax.naming.InitialContext.lookup(InitialContext.java:396)
at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:110)
... 11 more
Caused by: javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext [Root exception is java.lang.NullPointerException]
at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:276)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:430)
... 14 more
Caused by: java.lang.NullPointerException
at com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(SerialContext.java:297)
at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:271)
... 15 more

drrevis
Offline
Joined: 2008-07-12

Do you have any suggestions on what else I can check or try to get beyond this? I still haven't been able to. I tried having the EJB module access the database directly instead of using a JPA project and that didn't help. I tried using javax.mysql.DataSource instead of javax.mysql.XADataSource and that also didn't help. Should I try using topLink instead of eclipseLink?

Has anyone else been able to use this setup successfully? I would appreciate any help at all. Seems unlikely that this won't work with the new server since I'm not doing anything other than basic access, but I just don't know what else to try.

Thanks,
Renee

Ludovic Champenois

On 2/4/10 2:14 PM, glassfish@javadesktop.org wrote:
> Do you have any suggestions on what else I can check or try to get beyond this? I still haven't been able to. I tried having the EJB module access the database directly instead of using a JPA project and that didn't help. I tried using javax.mysql.DataSource instead of javax.mysql.XADataSource and that also didn't help. Should I try using topLink instead of eclipseLink?
>
> Has anyone else been able to use this setup successfully? I would appreciate any help at all. Seems unlikely that this won't work with the new server since I'm not doing anything other than basic access, but I just don't know what else to try.
>
>
Can you see if
http://www.creasystem.ch/development-using-eclipse-glassfish-and-mysql
helps?

Ludo
> Thanks,
> Renee
> [Message sent by forum member 'drrevis' (renee@leadingstep.com)]
>
> http://forums.java.net/jive/thread.jspa?messageID=384881
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net

drrevis
Offline
Joined: 2008-07-12

Thanks for the suggestion, but no, it doesn't help. That example uses GlassFish v2 which I have been able to do with no problems for quite a while now. It's GlassFish v3 specifically that isn't working. I also did go through all of the suggested steps in that example anyway, and I've done all of those things, but still get a null EntityManager from the injection.

One other point to note is that I'm trying to use this with Flex 4 and so I have the Flash Builder plugin installed in the GlassFish Bundle. Doesn't seem like that should affect the JPA part of things, but just wanted to mention it.

Renee

Marina Vatkina

This is the cause of the problem:

Caused by: java.lang.NullPointerException
at
com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(SerialContext.java:297)
at
com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:271)

Are you sure you have v3 installed correctly?

thanks,
-marina

glassfish@javadesktop.org wrote:
> Thanks for the suggestion, but no, it doesn't help. That example uses GlassFish v2 which I have been able to do with no problems for quite a while now. It's GlassFish v3 specifically that isn't working. I also did go through all of the suggested steps in that example anyway, and I've done all of those things, but still get a null EntityManager from the injection.
>
> One other point to note is that I'm trying to use this with Flex 4 and so I have the Flash Builder plugin installed in the GlassFish Bundle. Doesn't seem like that should affect the JPA part of things, but just wanted to mention it.
>
> Renee
> [Message sent by forum member 'drrevis' (renee@leadingstep.com)]
>
> http://forums.java.net/jive/thread.jspa?messageID=385046
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net

drrevis
Offline
Joined: 2008-07-12

I've tried so many things that at this point I'm not sure of much ;-).

I had downloaded glassfish-tools-bundle-for-eclipse-1.2.dmg and installed from that. Once that was finished, I added a com.adobe.flexbuilder.feature.core.nl1.link file which points to the Flash Builder plugin.

Before that, I was trying to use a version of Galileo Eclipse and have it download the updates for GlassFish v3, while using the Flex Builder plugin (i.e., Flex 3), but I kept running into problems and so using the bundled version of GlassFish and Eclipse finally seemed to work. I wonder if something got messed up in the installation as a result of all of that?

I could delete the entire GlassFish/Eclipse directory and try again from scratch, but it seems like that's what I had already done to get this far. Is that what you would suggest? Anything else I should try or look at in more detail before going through that process again (i.e., in case I'm likely to end up back in the same position again)? Is there anything that gets installed anywhere else that I should delete before trying to re-install again?

Marina Vatkina

Can it be that you accidentally got outdated updates to GlassFish v3?

thanks,
-marina

glassfish@javadesktop.org wrote:
> I've tried so many things that at this point I'm not sure of much ;-).
>
> I had downloaded glassfish-tools-bundle-for-eclipse-1.2.dmg and installed from that. Once that was finished, I added a com.adobe.flexbuilder.feature.core.nl1.link file which points to the Flash Builder plugin.
>
> Before that, I was trying to use a version of Galileo Eclipse and have it download the updates for GlassFish v3, while using the Flex Builder plugin (i.e., Flex 3), but I kept running into problems and so using the bundled version of GlassFish and Eclipse finally seemed to work. I wonder if something got messed up in the installation as a result of all of that?
>
> I could delete the entire GlassFish/Eclipse directory and try again from scratch, but it seems like that's what I had already done to get this far. Is that what you would suggest? Anything else I should try or look at in more detail before going through that process again (i.e., in case I'm likely to end up back in the same position again)? Is there anything that gets installed anywhere else that I should delete before trying to re-install again?
> [Message sent by forum member 'drrevis' (renee@leadingstep.com)]
>
> http://forums.java.net/jive/thread.jspa?messageID=385073
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net

drrevis
Offline
Joined: 2008-07-12

According to the admin console, I'm running build 74.2. In looking at the list of available downloads, I'm guessing that corresponds to 74b which does look like the latest. Is that right?

Marina Vatkina

Can you accidentally override any jars with your add-ons?

thanks,
-marina

glassfish@javadesktop.org wrote:
> According to the admin console, I'm running build 74.2. In looking at the list of available downloads, I'm guessing that corresponds to 74b which does look like the latest. Is that right?
> [Message sent by forum member 'drrevis' (renee@leadingstep.com)]
>
> http://forums.java.net/jive/thread.jspa?messageID=385091
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net

drrevis
Offline
Joined: 2008-07-12

I don't think so. The only thing I did to install the plugin was add a file in the dropins folder called com.adobe.flexbuilder.feature.core.nl1.link. It contains one line which is:

path=/Applications/Adobe Flash Builder Plug-in Beta 2

and that pulls in the flash builder plugin. Doesn't seem like it would override any jars related to JPA.

drrevis
Offline
Joined: 2008-07-12

Well, I've finally got past this problem and thought I would post what I did just in case in helps anyone else.

I'm not completely sure, but I think the base problem was the version of Java running on my Mac. I had the update for Java which gave me 1.6.0_17 as is needed by this version of Eclipse, but something wasn't set up correctly. When I did "java -version" at the terminal, it would tell me I was running the right version, but when I ran a test program from a browser window, it said I was still running 1.5.x. I even went to the Genius Bar at the Apple store and they couldn't figure out why it wasn't picking up 1.6, but I ended up just upgrading to Mac OS X 10.6.2 which runs the correct version of Java by default (I was running 10.5.8 previously).

After I upgraded, things still didn't work, so I completely deleted the GlassFish Tools bundle and Flash Builder 4 and reinstalled everything from scratch. I think it did change something because things seemed to operate slightly differently (e.g., the GlassFish v3 server was available by default and didn't have to be downloaded). Still, when I tried to run my little test app, it still couldn't access the database.

Finally, I randomly realized that I had the EntityManager injection located in a service file rather than in the bean file directly and once I moved it to the bean, the EntityManager variable was injected correctly. I'm not sure which of these things actually caused the problem or if it was a combination of all of them, but it finally happens correctly.

The last issue I had to get past was figuring out where the mysql-connector-java-5.1.7-bin.jar file should be. I put it in ~workspace/.metadata/.plugins/com.sun.enterprise.jst.server.sunappsrv92/domain1/lib/ext/ and restarted the server and was then finally able to access the database!