Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » DB Access problem(Intermittent failure to read DB)
DB Access problem [message #1438725] Mon, 06 October 2014 12:06 Go to next message
Neil Cohen is currently offline Neil CohenFriend
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 Go to previous messageGo to next message
Rick Curtis is currently offline Rick CurtisFriend
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 #1439658 is a reply to message #1439619] Tue, 07 October 2014 11:26 Go to previous messageGo to next message
Neil Cohen is currently offline Neil CohenFriend
Messages: 12
Registered: June 2012
Junior Member
I probably wasn't clear in the original post - you are absolutely correct - there is nothing wrong with the database itself.

As for Tomcat - when we restart this set of applications, we kill the Tomcat process, remove all the code - war files and directories from /Tomcat/webapps and reload everything from scratch. That is why this is driving me nuts - either it should always find this particular entity, or it should NEVER find it - right? I'm not changing anything - just killing Tomcat and restarting it...

Thanks,

nbc
Re: DB Access problem [message #1440115 is a reply to message #1439658] Wed, 08 October 2014 00:48 Go to previous messageGo to next message
Rick Curtis is currently offline Rick CurtisFriend
Messages: 24
Registered: September 2014
Location: Rochester, MN
Junior Member
What happens if you update an existing Entity? Is that change picked up without having to do the kill/clean/restart business?
Re: DB Access problem [message #1440446 is a reply to message #1440115] Wed, 08 October 2014 11:27 Go to previous messageGo to next message
Neil Cohen is currently offline Neil CohenFriend
Messages: 12
Registered: June 2012
Junior Member
Not 100% sure what you mean. If my program updates a row in the database (add/remove a record, update a record) that works fine. If you mean change the code or redefine the table, then yes, I kill tomcat and do a complete reload. My programs that access this database but not this particular table have no problems, and the program that accesses the table works fine IF it reads the table correctly the first time it is accessed. If not, killing and restarting Tomcat seems to get it to read the table correctly and then it works as long as the system runs...

nbc
Re: DB Access problem [message #1440545 is a reply to message #1440446] Wed, 08 October 2014 13:45 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
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 Go to previous messageGo to next message
Neil Cohen is currently offline Neil CohenFriend
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
Re: DB Access problem [message #1441359 is a reply to message #1440559] Thu, 09 October 2014 16:09 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
The query is just the first thing you do on the class, so it is the first time that entity is accessed in the persistence unit - I'm fairly sure you would get an exception stating this class is not in the persistence unit if you changed your app so that a persist call to Foo is first. It is unlikely that your table/insert modifications have anything to do with the problem; the issue seems likely due to how classloaders are picking up the persistence unit when reloadTomcat.sh is called.

Check how your persistence unit is packaged, and if there are any other persistence units of the same name that might be pickedup that exclude the class causing the problem. You will need to check the classloaders and see what might be interfering or why your class isn't found in the persistence unit.
Re: DB Access problem [message #1441453 is a reply to message #1441359] Thu, 09 October 2014 19:11 Go to previous message
Neil Cohen is currently offline Neil CohenFriend
Messages: 12
Registered: June 2012
Junior Member
You are probably correct - if the first call to the class was to save a new record, I suspect that would fail (intermittently...)

The persistence.xml file contains this:

<persistence-unit name="XXXX" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <class>com.vrsn.rules.Alerts</class>
    <class>com.vrsn.rules.Hostnames</class>
etc. etc.


The Hostnames class is the one that is affected. I understand what you are suggesting - but I still don't see how it can work intermittently - either the class is there or it isn't... How can it do both?

The persistence.xml file does have several different sections with different persistence units - for different databases that I access. But this is the only table that has ever given me a problem...

nbc
Previous Topic:Exception Description: Missing descriptor for [class strategysvcs.entity.StrategyProfileDetails
Next Topic:I'm getting a Eclipselink-93 while trying to use a relationship in an embeddable.
Goto Forum:
  


Current Time: Thu Apr 25 01:59:37 GMT 2024

Powered by FUDForum. Page generated in 0.03842 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top