Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » DatabaseAccessor not connected and Eingabe/Ausgabe-Fehler(Exceptions while iterate through a Result List of retrieved objects)
DatabaseAccessor not connected and Eingabe/Ausgabe-Fehler [message #727684] Wed, 21 September 2011 16:01 Go to next message
Mike  is currently offline Mike
Messages: 4
Registered: September 2011
Junior Member
Hey all

I wrote an own java CRUD application, using PostgreSQL. I have now two serious problem and I cannot find a solution for them Sad Both problems has todo with the database

connection.

But let me introduce shortly my application: It's a simple customer/contract management system (nothing special). It's possible to manage customers and related contracts.

A customer has several sub-objects like ID (I mean ID such as a passport), official documents (Permits) and the result is a contract document.

Now what is the problem? In my application there is a use-case that requires to search for customers and display their information (like address, name, ...) and also some

information from their sub-objects like ID-Number, Validity of e.g. the passport, and the validity of the official document attached to the customer. On the database

there are 3 tables for that (Person, Identification, Permit) and a fourth table that stores the contracts. I use the following code to search customers returning a result

set in the form of a List<Person>. It seems that when I iterate through these list, a "layer" in my whole stack tries to reload data from database (I thinks it's the

EclipseLink that tries to load additional information of a person).

And then it happens: exception-2.txt occures ([...]DatasourceAccessor.java:309[...])
The line of code that causes the problem can be found in DatasourceAccessor.java in the EclipseLink-Source! It's (wow what a surprise...):

throw DatabaseException.databaseAccessorNotConnected();

because the "if (this.usesExternalConnectionPooling)" seems to be false!

But why this is, I don't know and I was unable to find till now a solution.

The exception in the file exception-1.txt happens not often and also random! Also for this I have no solution. A lot of forum entries on the Internet I found that says

there is something wrong with the network, but since the Postgresql-Database is installed on my local PC I think it's not that problem. Also firewalls (windows and other

firewall-software) should not be an issue, since I deactivated them. What I found is a strange entry in the logfile of postgresqs says:

2011-09-21 20:52:42 CEST LOG: unerwartetes EOF auf Client-Verbindung
2011-09-21 20:52:42 CEST LOG: konnte Daten vom Client nicht empfangen: No connection could be made because the target machine actively refused it.

But why the target machine actively should refuse it? I don't know

Let me show also show you some code that selects the List of customers that I iterate:

@Override
public List<Person> searchCustomer(String[] searchItems, ECustomerSearchCriterion searchCriterion) throws SQLException
{
List<Person> returnListPerson = new ArrayList<Person>();
Query query = null;
int ctr = 0;

try {
entityManager = DBHelper.getInstance().getMainEntityManager(connectionProperties);
// Compose the Select Statement the old fashioned way:
// SELECT p FROM Person p WHERE p.personState = 1 AND p.personType = 'C'
// ... some Code with error handlings about the parameter
@SuppressWarnings("unchecked") List<Person> resultListPersons = query.getResultList(); //NOI18N
returnListPerson = resultListPersons;
}
catch (Exception e) {
throw new SQLException(e);
}
finally {
if (entityManager != null && entityManager.isOpen()) {
entityManager.close();
}
}

if (returnListPerson.isEmpty()) {
return null;
}
else {
return returnListPerson;
}
}

As you can see, nothing special! When this function returns there is no further database-access (from my side, like using EntityManager or something like that, ...). The

code happens after the call of this function is simply iterate through the returnListPerson and access the database objects in it (to display them).

A word about versions and libraries:

- Operating System: Windows 7 Ultimate English, 64bit
- Java-Version: 1.6.0_26 Java(TM) Runtime Environment (build 1.6.0_26-b03), Java HotSpot (TM) 64-Bit Server VM (build 20.1-b02, mixed mode)
- NetBeans Development Environment 7.0 (Build 201104080000)
- Postgres-Java-Driver: postgresql-9.0-801.jdbc4.jar
- Javax-Persistence (JPA): javax.persistence_2.0.3v201010191057.jar
- Eclipselink: ecliselink.jar (MANIFEST.MF says "Implementation-Version: 2.3.0.v20110604-r9504
- Postgresql: select version(); says PostgreSQL 9.0.3, compiled by Visual C++ build 1500, 64-bit

So, that's what I can give you for information. I'm looking since a couple of weeks through the internet about this problem and haven't found a solution till now Sad I

start to dispair about this problem Sad

Hope you can help!
Greetings, Mike
  • Attachment: files.zip
    (Size: 17.31KB, Downloaded 67 times)
Re: DatabaseAccessor not connected and Eingabe/Ausgabe-Fehler [message #728096 is a reply to message #727684] Thu, 22 September 2011 10:20 Go to previous messageGo to next message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

>> DBHelper.getInstance().getMainEntityManager(connectionProperties);

What does this do exactly and why? It seems you are getting a specific connection per request (not using a connection pool)??

Normally connection pooling is used.

You are also closing the EntityManager before returning the objects, as they have relationships that will need to be fetched, these will need to reconnect this closed entity manager.

Try using a connection pool, or use join fetching or a LoadGroup to instantiate everything you need before returning.


James : Wiki : Book : Blog : Twitter
Re: DatabaseAccessor not connected and Eingabe/Ausgabe-Fehler [message #728202 is a reply to message #728096] Thu, 22 September 2011 13:58 Go to previous messageGo to next message
Mike  is currently offline Mike
Messages: 4
Registered: September 2011
Junior Member
The line you asked for creates an EntityManager when it's not already created and stores in in a member variable.


public synchronized EntityManager getMainEntityManager(Properties connection) throws PersistenceException
  {
    if (mainEntityManager == null || !mainEntityManager.isOpen()) {
      mainEntityManager = getNewEntityManager(connection);
    }
    return mainEntityManager;
  }

public synchronized EntityManager getNewEntityManager(Properties connection) throws PersistenceException
  {
    EntityManager entity = Persistence.createEntityManagerFactory("GSDomainModelModulePU", connection).createEntityManager(); // NOI18N
    if (entity == null) {
      Logger.getLogger(DBHelper.class.getName()).log(Level.WARNING, "Creating entity manager has failed. I'll retry one time more!"); // NOI18N
      entity = Persistence.createEntityManagerFactory("GSDomainModelModulePU", connection).createEntityManager(); // NOI18N
      if (entity == null) {
        Logger.getLogger(DBHelper.class.getName()).log(Level.SEVERE, "The entity manager can definitly not be created. This a fatal failure!"); // NOI18N
        throw new PersistenceException("Unable to create an entity manager!"); // NOI18N
      }
    }
    return entity;
  }


Yes, I close the EntityManager before returning the list of objects. I thought that's correct since every example I found (also with sub-objects) do it so. So I think it's correct?

How do I use "connection pooling"? You mean just to write it by myself creating several entity managers using them or so?
Re: DatabaseAccessor not connected and Eingabe/Ausgabe-Fehler [message #728255 is a reply to message #728202] Thu, 22 September 2011 15:44 Go to previous messageGo to next message
Mike  is currently offline Mike
Messages: 4
Registered: September 2011
Junior Member
I just tried to let the entity manager open, but it does not make any difference...
Re: DatabaseAccessor not connected and Eingabe/Ausgabe-Fehler [message #728258 is a reply to message #728202] Thu, 22 September 2011 15:44 Go to previous messageGo to next message
Mike is currently offline Mike
Messages: 49
Registered: July 2009
Member
I just tried to let the entity manager open, but it does not make any difference...
Re: DatabaseAccessor not connected and Eingabe/Ausgabe-Fehler [message #729587 is a reply to message #728255] Mon, 26 September 2011 11:23 Go to previous messageGo to next message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Include the full exception stack trace.


James : Wiki : Book : Blog : Twitter
Re: DatabaseAccessor not connected and Eingabe/Ausgabe-Fehler [message #729597 is a reply to message #728255] Mon, 26 September 2011 11:23 Go to previous messageGo to next message
James is currently offline James
Messages: 272
Registered: July 2009
Senior Member
Include the full exception stack trace.

--
James : http://wiki.eclipse.org/EclipseLink : http://en.wikibooks.org/wiki/Java_Persistence : http://java-persistence-performance.blogspot.com/
Re: DatabaseAccessor not connected and Eingabe/Ausgabe-Fehler [message #733767 is a reply to message #727684] Wed, 05 October 2011 11:15 Go to previous messageGo to next message
Mike  is currently offline Mike
Messages: 4
Registered: September 2011
Junior Member
The full stack trace, logfiles and all I have is located in the files.zip

But anyway here:
Local Exception Stack:
Exception [EclipseLink-4005] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.DatabaseException
Exception Description: DatabaseAccessor not connected.
at org.eclipse.persistence.exceptions.DatabaseException.databaseAccessorNotConnected(DatabaseException.java:116)
at org.eclipse.persistence.internal.databaseaccess.DatasourceAccessor.incrementCallCount(DatasourceAccessor.java:309)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:579)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:535)
at org.eclipse.persistence.internal.sessions.AbstractSession.basicExecuteCall(AbstractSession.java:1702)
at org.eclipse.persistence.sessions.server.ServerSession.executeCall(ServerSession.java:566)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:207)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:193)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeSelectCall(DatasourceCallQueryMechanism.java:264)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.selectAllRows(DatasourceCallQueryMechanism.java:646)
at org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllRowsFromTable(ExpressionQueryMechanism.java:2592)
at org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllRows(ExpressionQueryMechanism.java:2551)
at org.eclipse.persistence.queries.ReadAllQuery.executeObjectLevelReadQuery(ReadAllQuery.java:418)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeDatabaseQuery(ObjectLevelReadQuery.java:1097)
at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:829)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:1056)
at org.eclipse.persistence.queries.ReadAllQuery.execute(ReadAllQuery.java:390)
at org.eclipse.persistence.internal.sessions.AbstractSession.internalExecuteQuery(AbstractSession.java:2816)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1501)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1483)
at org.eclipse.persistence.internal.indirection.QueryBasedValueHolder.instantiate(QueryBasedValueHolder.java:98)
at org.eclipse.persistence.internal.indirection.QueryBasedValueHolder.instantiate(QueryBasedValueHolder.java:88)
at org.eclipse.persistence.internal.indirection.DatabaseValueHolder.getValue(DatabaseValueHolder.java:88)
at org.eclipse.persistence.internal.indirection.UnitOfWorkValueHolder.instantiateImpl(UnitOfWorkValueHolder.java:161)
at org.eclipse.persistence.internal.indirection.UnitOfWorkValueHolder.instantiate(UnitOfWorkValueHolder.java:222)
at org.eclipse.persistence.internal.indirection.DatabaseValueHolder.getValue(DatabaseValueHolder.java:88)
at org.eclipse.persistence.indirection.IndirectList.buildDelegate(IndirectList.java:238)
at org.eclipse.persistence.indirection.IndirectList.getDelegate(IndirectList.java:408)
at org.eclipse.persistence.indirection.IndirectList.isEmpty(IndirectList.java:483)
at ch.domain.product.domainmodel.Person.getActualIdentification(Person.java:504)
at ch.domain.product.office.contractsmodule.ui.counterpartpanel.CounterpartSelectionPanel.currentCounterpartChanged(CounterpartSelectionPanel.java:140)
at ch.domain.product.office.contractsmodule.ui.counterpartpanel.CounterpartSelectionPanel.access$000(CounterpartSelectionPanel.java:34)
at ch.domain.product.office.contractsmodule.ui.counterpartpanel.CounterpartSelectionPanel$1.propertyChange(CounterpartSelectionPanel.java:110)
at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:339)
at ch.domain.product.office.contractsmodule.ui.counterpartpanel.CounterpartSelectionDetailModel.setCounterpart(CounterpartSelectionDetailModel.java:205)
at ch.domain.product.office.contractsmodule.ui.counterpartpanel.CounterpartSelectionPanel.jButtonBackwardActionPerformed(CounterpartSelectionPanel.java:552)
at ch.domain.product.office.contractsmodule.ui.counterpartpanel.CounterpartSelectionPanel.access$500(CounterpartSelectionPanel.java:34)
at ch.domain.product.office.contractsmodule.ui.counterpartpanel.CounterpartSelectionPanel$4.actionPerformed(CounterpartSelectionPanel.java:331)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.AbstractButton.doClick(AbstractButton.java:357)
at javax.swing.plaf.basic.BasicRootPaneUI$Actions.actionPerformed(BasicRootPaneUI.java:191)
at javax.swing.SwingUtilities.notifyAction(SwingUtilities.java:1639)
at javax.swing.JComponent.processKeyBinding(JComponent.java:2851)
at javax.swing.KeyboardManager.fireBinding(KeyboardManager.java:267)
at javax.swing.KeyboardManager.fireKeyboardAction(KeyboardManager.java:216)
at javax.swing.JComponent.processKeyBindingsForAllComponents(JComponent.java:2928)
at javax.swing.JComponent.processKeyBindings(JComponent.java:2920)
at javax.swing.JComponent.processKeyEvent(JComponent.java:2814)
at java.awt.Component.processEvent(Component.java:6065)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4651)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4481)
at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1850)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:712)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:990)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:855)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:676)
at java.awt.Component.dispatchEventImpl(Component.java:4523)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4481)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:643)
at java.awt.EventQueue.access$000(EventQueue.java:84)
at java.awt.EventQueue$1.run(EventQueue.java:602)
at java.awt.EventQueue$1.run(EventQueue.java:600)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
at java.awt.EventQueue$2.run(EventQueue.java:616)
at java.awt.EventQueue$2.run(EventQueue.java:614)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:613)
at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:148)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

Re: DatabaseAccessor not connected and Eingabe/Ausgabe-Fehler [message #734064 is a reply to message #733767] Thu, 06 October 2011 10:56 Go to previous message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

You don't seem to be storing the factory anywhere. This means that when it garbage collects it will be disconnected.

You need to store the factory in a static or context variable until you are done with it.


James : Wiki : Book : Blog : Twitter
Re: DatabaseAccessor not connected and Eingabe/Ausgabe-Fehler [message #734085 is a reply to message #733767] Thu, 06 October 2011 10:56 Go to previous message
James is currently offline James
Messages: 272
Registered: July 2009
Senior Member
You don't seem to be storing the factory anywhere. This means that when it garbage collects it will be disconnected.

You need to store the factory in a static or context variable until you are done with it.

--
James : http://wiki.eclipse.org/EclipseLink : http://en.wikibooks.org/wiki/Java_Persistence : http://java-persistence-performance.blogspot.com/
Previous Topic:Parameterized PersistenceContext in EJB 3.1
Next Topic:pingsql
Goto Forum:
  


Current Time: Mon Sep 01 07:29:11 EDT 2014

Powered by FUDForum. Page generated in 0.03083 seconds