[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [eclipselink-users] Workaround? for: EntityManagerFactoryImpl throwing null pointer exception on connection
|
Hi Tom,
You are right, I should have tried something like that.
Should have looked for something useful happening the close()
before the exception is thrown. Anyway,
the workaround now solves the problem in my version
of your pseudo code.
I'll get back to integrating it into my
application test cases in a few days. My questions are answered.
Again, thanks for your knowledgeable, clear and patient assistance
with this.
Cheers,
Gordon
Tom Ware wrote:
Have you tried code like the following:
try{
emf.close();
} finally {
if (SessionManager.getManager().getSessions().contains((<sessionName>){
SessionManager.getManager().getSessions().remove(<sessionName>);
}
}
Sorry if that was not clear from the comment in the bug.
-Tom
Gordon Ferguson wrote:
Yes I tried that, but the close() throws an exception (the other bug).
So this variant does not close() the emf. It removes the session
after closing the EntityManager.
Gordon
Tom Ware wrote:
Where are you removing the session? Is it immediately after the "close"?
-Tom
Gordon Ferguson wrote:
Tom, to follow up on this:
I found the workaround you posted with the bug report and
tried it but still get a socket reset exception when I try
to work with the connection.
Gordon
Gordon Ferguson wrote:
Hi Tom,
I will follow those bugs, thanks.
And I'd be glad for some help with a workaround (if
it's not too complicated).
Thanks,
Gordon
Tom Ware wrote:
Hi Gordon,
I have filed the following bugs. I am going to recommend to the
team that we address at both of them for our 1.1 release:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=256284
https://bugs.eclipse.org/bugs/show_bug.cgi?id=256296
There is a workaround available for the EMF version. I involves
using EclipseLink specific API to ensure a copy of the underlying
session is not stored after your EMF closes. If you want, I can
help you with that workaround.
-Tom
Gordon Ferguson wrote:
Here you go. I have not reviewed these, hope they help.
Gordon
Tom Ware wrote:
Hi Gordon,
You you increase your logging level to FINEST and resend the
output of the failures.
You can user the persistence unit property
eclipselink.logging.level=FINEST to set your logging level:
<property name="eclipselink.logging.level" value="FINEST"/>
-Tom
Gordon Ferguson wrote:
Hi Tom,
Short answer seems to be: the difference is how we
force the diconnection.
I have attached some files to document this.
Upshot is
(1) I was able to replicate your successful restart after an
orderly stop/start of MySQL running locally.
(2) The restart does not succeed when network connectivity to a
remote oracle instance is broken and restored.
(3) The EMF variant, closing and recreating the entire factory,
has different, perhaps more informative, symptoms.
Attached are: the java test file, console output from the success,
console output from the failure, and console output from the
ORACLE failure using the EMF variant. The only difference in
the java
code between the two was to swap persistent unit names.
In the mysql case I used the database manager to stop/start.
In the ORACLE case I disconnected/reconnnected the VPN we use.
The EMF failure had problems with closing the EMF -- it apparently
tried to access the database as part of the close() and failed.
And
it apparently did not clear out the old EM:
Caused by: Exception [EclipseLink-28009] (Eclipse Persistence
Services - 1.0.2 (Build 20081024)):
org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Attempted to redeploy a session named
file:/D:/projs/costar-1.3/jclass/-Cloaks-dev-prod without
closing it.
Thanks,
Gordon
Tom Ware wrote:
Hi Gordon,
FYI: By default, EclipseLink will create a connection pool
for you. The settings you have below affect the connection
limits, but do not affect whether or not there is a connection
pool.
I cannot recreate the issue you are having. Can you tell me
what is different about what I am doing.
I am running two simple tests on MySQL. Here is the pseudo code:
// This is the case where the whole EMF is recreated
public void testEMFCloseAndOpen(){
Employee emp = null;
// creates an EMF for PU default and then creates an
EM from it
EntityManager em = createEntityManager();
em.find(Employee.class, 1);
try{
em.getTransaction().begin();
// shut down DB prior to this line
emp = new Employee();
em.persist(emp);
em.getTransaction().commit();
} catch (Exception e){
// get exception here after a number of retries
e.printStackTrace();
}
getEntityManagerFactory().close();
// restart the db prior to this line
em = createEntityManager();
em.getTransaction().begin();
emp = new Employee();
em.persist(emp);
em.getTransaction().commit();
}
// this is the case where just the EM is recreated
public void testEMCloseAndOpen(){
Employee emp = null;
EntityManager em = createEntityManager();
em.find(Employee.class, 1);
try{
em.getTransaction().begin();
// shut down DB prior to this line
emp = new Employee();
em.persist(emp);
em.getTransaction().commit();
} catch (Exception e){
// get exception here after a number of retries
e.printStackTrace();
}
em.close();
// restart the db prior to this line
em = createEntityManager();
em.find(Employee.class, 1);
em.getTransaction().begin();
emp = new Employee();
em.persist(emp);
em.getTransaction().commit();
}
-Tom
Gordon Ferguson wrote:
Tom Ware wrote:
Hi Gordon,
It sounds like you are using the default EclipseLink
connection pool.
No doubt. I did try with
snip ...
emfProperties.put(JDBC_READ_CONNECTIONS_MIN, "1");
emfProperties.put(JDBC_WRITE_CONNECTIONS_MIN, "1");
// Ensure that no server-platform is configured
emfProperties.put(TARGET_SERVER, TargetServer.None);
etc
But the problem remained.
Is there any particular reason you have chosen to close
your EntityManagerFactory? What happens if you simply
acquire a new entityManager from the same factory? Do you
have problems with the connection?
I did try some variations. Closing and recreating everything
seemed
the most likely way to get a fresh start. Shot in the dark in
other words.
I have just (re)tried: close the EntityManager and get a new
one from
the existing factory; the problem appears unchanged.
One, perhaps interesting, note about the stack trace: EL logs
a successful login before throwing the null pointer exception.
I don't see the login success when the underlying network
connection is unavailable.
Thanks again,
Gordon
-Tom
Gordon Ferguson wrote:
Tom Ware wrote:
Hi Gordon,
Are you running in JavaSE or in some kind of container?
JavaSE
Are you using a connection pool?
not as far as I know. Should I be?
Is it external to EclipseLink or EclipseLink's own
connection pool?
n/a?
How does your test obtain the connection and reestablish
it?
>> emf =
Persistence.createEntityManagerFactory(persistenceUnitLabel);
>> entityManager = emf.createEntityManager();
I am not surprised that the scenario you are describing
is causing issues. EclipseLink has some strategies you can
use to reestablish connections, but doing it somewhere
EclipseLink is completely unaware of could cause an issue.
So, what is the most simple solution? The actual
application runs in Tomcat; database is sometimes Oracle
sometimes MySQL. (The JNDI stuff
seems to multiply code complexity, do I really have to go
there? )
Many thanks,
Gordon
-Tom
Gordon Ferguson wrote:
Hi Tom,
It has been a few weeks but I'm back to this question.
The basic scenario I'm having trouble with is recovery
after a
SQLException: Io exception: The Network Adapter could not
establish the connection ...
My test case forces that error and then restores the
underlying
connection. I then want to get EclipseLink going again.
Is there an api to get a (new?) working EntityMangager at
this point?
What I'm trying is invoke close() both the EntityManager
and the
EntityManagerFactory. (Nothing thrown by this.) Then I
repeat this code:
protected void privateInit(String persistenceUnitLabel,
...) {
emf =
Persistence.createEntityManagerFactory(persistenceUnitLabel);
entityManager = emf.createEntityManager();
...
}
and the first line creates the stack trace below.
Thanks for any suggestions,
Gordon
Tom Ware wrote:
Hi Gordon,
If EclipseLink is following the expected code path,
the structConverters should be initialized inside the
"if (state == STATE_PREDEPLOYED) {" code block below
where the structConverters variable is being defined on
the following line:
structConverters = processor.getStructConverters();
If you are not getting into that if statement and
still getting to "addStructConverters(session,
structConverters)" something strange is occurring with
your deployment. It is hard to say what the problem is
without more information about the symptoms of the
problem you are seeing.
-Tom
Gordon Ferguson wrote:
Hello,
I'm using the SE approach and testing my 'recovery
after error' logic.
I see the exception listed below. I looked at the code
and found
EntityManagerSetupImpl.deploy() method initializes
structConverters to null in l.189
Then, in l. 319 passes that null to
addStructConverters(...) which tries to add to the
(null) List.
List<StructConverter> structConverters = null;
SO, I'm wondering if this is just a coding typo or if I
need to dig deeper
into why I'm in this state?
Any suggestions would be appreciated.
Thanks,
Gordon
Listing:
[EL Info]: 2008.10.30
11:53:03.781--ServerSession(653967)--EclipseLink,
version: Eclipse Persistence Services - 1.0.2 (Build
20081024)
Exception in thread "main" [EL Info]: 2008.10.30
11:53:10.328--ServerSession(653967)--file:/D:/projs/costar-1.3/jclass/-True-DevDev
login successful
costar.dbaccess.DbAccessException: Could not access
database.
at
costar.dbaccess.jpa.CoStarJpaAccess.privateInit(CoStarJpaAccess.java:82)
at
costar.dbaccess.jpa.CoStarJpaAccess.<init>(CoStarJpaAccess.java:53)
at
costar.dbaccess.jpa.test.JpaConnectionCheckerChecker.main(JpaConnectionCheckerChecker.java:104)
Caused by: java.lang.NullPointerException
at
org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.addStructConverters(EntityManagerSetupImpl.java:319)
at
org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:249)
at
org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:69)
at
org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:118)
at
org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:112)
at
org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:100)
at
costar.dbaccess.jpa.CostarJpaFacade.<init>(CostarJpaFacade.java:47)
at
costar.dbaccess.jpa.CoStarJpaAccess.privateInit(CoStarJpaAccess.java:80)
... 2 more
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
------------------------------------------------------------------------
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
------------------------------------------------------------------------
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
------------------------------------------------------------------------
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users