Ok, I don't want to try your test case, simply because I don't have the same setup like you have (database, java, database version, data in your database, ect).
But: Can you try to execute all these steps directly in psql and see, if this works?
Hey all
I wrote an own java CRUD application, using PostgreSQL. I have now two serious problem and I cannot find a solution for themBoth 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(connec tionProperties);
// 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
You can download a ZIP with the files mentioned above HERE -> http://www.klische.ch/files.zip (since the upload of files on this page won't work
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 nowI start to dispair about this problem
Hope you can help!
Greetings, Mike
Ok, I don't want to try your test case, simply because I don't have the same setup like you have (database, java, database version, data in your database, ect).
But: Can you try to execute all these steps directly in psql and see, if this works?
Xandrian: Kurz gesagt: Du hast ein falsches Konzept und willst nicht auf ads hören
Jetzt NEU: PostgreSQL - Datenbankpraxis für Anwender, Administratoren und Entwickler
PostgreSQL Service & Support
How long does it take to load the data from the database?
Xandrian: Kurz gesagt: Du hast ein falsches Konzept und willst nicht auf ads hören
Jetzt NEU: PostgreSQL - Datenbankpraxis für Anwender, Administratoren und Entwickler
PostgreSQL Service & Support
About... 2 or 3 Seconds to load a set of approx. ~2200 Records. And after that it may take several minutes to browse through them manually. Thing is: Sometimes i fetch the 2200 Records press quickly after the fetch the button to iterate through the records and sometimes it takes 2 Seconds until i get the error, and sometimes it takes... 10 seconds or so (and the fetching time of the initial load of the records is still the same).
I read somewhen something about a 15 Second Session timeout (or was is the connection timeout). I sure hit that limit somewhen, but then the error should appears very predictable after this amount of time. And it do not behave like this...
The Java-Code that throws the error inside EclipseLink library is the following one:
Obviously the "usesExternalConnectionPooling" seems to be false. But why this is I don't know. If it's something I have to setup in the database environment (config), on level JPA/Eclipselink or somewhere. I don't know...Code:// If the connection is no longer connected, it may have timed out. if (this.datasourceConnection != null) { if (shouldCheckConnection && !isConnected()) { if (this.isInTransaction) { throw DatabaseException.databaseAccessorNotConnected(); } else { reconnect(session); } } } else { // If ExternalConnectionPooling is used, the connection can be re-established. if (this.usesExternalConnectionPooling) { reconnect(session); session.postAcquireConnection(this); currentSession = session; } else { // HERE IT HAPPENS!!! throw DatabaseException.databaseAccessorNotConnected(); } }![]()
The database has no connection timeouts which disconnect you after only some seconds.
my bet is the connection pooler - maybe it is using different connections for each query or has very small timeout settings.
Xandrian: Kurz gesagt: Du hast ein falsches Konzept und willst nicht auf ads hören
Jetzt NEU: PostgreSQL - Datenbankpraxis für Anwender, Administratoren und Entwickler
PostgreSQL Service & Support
Hmm, okay... Connection Pooler sounds logical.
And how can I configure this connection pooler or the timeout settings of this? Since I use windows I just downloaded a Windows Installer for PostgreSQL and pressed next, next, next finish. I have no advanced knowledge how to configure PostgreSQL. Its there an UI to configure this Connection Pooler / Connection Timeouts? Or must this be resolved in postresql.conf file?
The connection pooler comes with Java, not with PostgreSQL.
Therefore you have to solve this problem in Java.
I'm sorry, I avoid Java where possible, can't help you here.
Xandrian: Kurz gesagt: Du hast ein falsches Konzept und willst nicht auf ads hören
Jetzt NEU: PostgreSQL - Datenbankpraxis für Anwender, Administratoren und Entwickler
PostgreSQL Service & Support
Okay, then I'll try to get more information about the Java Connection Pooling mechanisms. Also "New-Land" for me...
Thanks for your help so far!
Links: Tobias Bauer - IT- und Funkdienstleistungen - Bilderrahmen-kaufen.de - Der Onlineshop für Bilderrahmen & Fotorahmen - Funkforum
Lesezeichen