DB Access problem [message #1438725] |
Mon, 06 October 2014 12:06 |
Neil Cohen Messages: 12 Registered: June 2012 |
Junior Member |
|
|
I have a set of Vaadin applications that all refer to a MySQL database, using EclipseLink 2.5.2. The applications all work fine.
Recently I added a new table to the database - it consists of an integer ID field and a couple of string fields - no different that several other tables I use. No foreign keys, nothing special.
The application that reads this table runs in a tomcat container. When the application starts, it opens the database and reads the contents of the table into a List<foo> object. I have tried making this the first table it reads, and I've switched the order so it reads one or two other tables first.
The code that reads the data looks like this - and is identical to the code that reads almost every table in the database..
public List<Foo> getAllFoo(){
em = getEntityManager();
Query q = em.createQuery("select f from Foo as f");
List<Foo> lf = q.getResultList();
em.close();
return(lf);
}
Couldn't be much simpler - and most of the time it works. But sometimes I get this error in the log file:
HTTP Status 500 - com.vaadin.server.ServiceException: java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager:
type Exception report
message com.vaadin.server.ServiceException: java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager:
description The server encountered an internal error that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: com.vaadin.server.ServiceException: java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager:
Exception Description: Problem compiling [select f from Foo as f].
[16, 28] The abstract schema type 'Foo' is unknown.
com.vaadin.server.VaadinServlet.service(VaadinServlet.java:239)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause
com.vaadin.server.ServiceException: java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager:
Exception Description: Problem compiling [select f from Foo as f].
[16, 28] The abstract schema type 'Foo' is unknown.
com.vaadin.server.VaadinService.handleExceptionDuringRequest(VaadinService.java:1459)
com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1413)
com.vaadin.server.VaadinServlet.service(VaadinServlet.java:237)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause
java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager:
Exception Description: Problem compiling [select f from Foo as f].
[16, 28] The abstract schema type 'Foo' is unknown.
org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1605)
com.verisign.montools.netcool.rules.db.Ctl_Foo.getAllFoo(Ctl_Foo.java:27)
com.verisign.montools.netcool.ncadmin.db.dbManager_NCAdmin.getFoo(dbManager_NCAdmin.java:23)
com.verisign.montools.netcool.ncadmin.NCAdminUI.getFoo(NCAdminUI.java:7)
It is failing to locate the table foo in the database. Restarting Tomcat - no code changes - causes it to work. No problems and it reads the table correctly. And it seems to happen occasionally, but not every time we restart the system. Once it works, it works continuously until the system is stopped and restarted.
So my question is - anyone see anything like this? Any idea what can cause it? The table exists, the data is there, the code works... usually....
Any suggestions appreciated - thanks in advance,
nbc
|
|
|
Re: DB Access problem [message #1439619 is a reply to message #1438725] |
Tue, 07 October 2014 10:34 |
Rick Curtis Messages: 24 Registered: September 2014 Location: Rochester, MN |
Junior Member |
|
|
Neil Cohen wrote on Mon, 06 October 2014 12:06
It is failing to locate the table foo in the database. Restarting Tomcat - no code changes - causes it to work. No problems and it reads the table correctly. And it seems to happen occasionally, but not every time we restart the system. Once it works, it works continuously until the system is stopped and restarted.
So my question is - anyone see anything like this? Any idea what can cause it? The table exists, the data is there, the code works... usually....
Any suggestions appreciated - thanks in advance,
nbc
The problem is that EclipseLink isn't recognizing the new Entity that you created. The exception has nothing to do with the database. Since restarting Tomcat seems to make the problem go away it sounds like something is going wrong with the auto-reload of your application.
I don't know much about Tomcat, but when you make an application update does the entire application redeploy or does it just hot swap some set of the classes? Either way, in this case you need to ensure that the entire app is redeployed.
|
|
|
|
|
|
Re: DB Access problem [message #1440545 is a reply to message #1440446] |
Wed, 08 October 2014 13:45 |
Chris Delahunt Messages: 1389 Registered: July 2009 |
Senior Member |
|
|
I think Rick was trying to get you to test to see if your issue only extends to using a read query on Foo, or if you experience a problem persisting or merging a Foo instance as well. If you attempt to persist a Foo instance, I'm betting you will get an exception stating it is not an entity in this persistence unit, which will indicate you are experiencing classloader issues - the class loader being used to load the persistence unit does not have access to the Foo class.
The fact that this error only happens sporadically under some restart conditions makes it difficult to guess what might be going wrong. I recommend turning on EclipseLink logging to finest or All, and tracking when the persistence unit first gets loaded. When the problem occurs, it will be important to figure out what classloader was used and what is different at these points as compared to when it works correct. How is the persistence unit packaged and how are you getting the EntityManager?
Best Regards,
Chris
[Updated on: Wed, 08 October 2014 13:46] Report message to a moderator
|
|
|
Re: DB Access problem [message #1440559 is a reply to message #1440545] |
Wed, 08 October 2014 14:14 |
Neil Cohen Messages: 12 Registered: June 2012 |
Junior Member |
|
|
Once the table is read, adding a record, or modifying one doesn't seem to be a problem... I will try turning on the logging.
One other thing we noticed. I have an update script that is currently running every morning.
It creates a sql file with over 100k insert statements that populate this particular table. I run the following in a shell script:
mysql -u u1 <sqlfile.txt
reloadTomcat.sh
The sqlfile basically deletes the contents of the table, and then loads the current data set. (this is done daily for testing purposes, but that will not be necessary down the road...) After the dataset is loaded, Tomcat is restarted (and the programs are copied into the webapps directory etc.) Is it possible that the database is somehow locking this table and my application can't access it right away? If that were the case, it would be intermittent, depending on how long the table was unavailable. And it might be that if we simply sleep for a few seconds after the sql reload the problem might go away (?????). We are going to try that for a couple of days and see what happens. I'm not sure this is an issue, but I have not come up with anything else either... If this happens to work, I'll let you know...
Thanks for the suggestions so far...
nbc
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03842 seconds