Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » EclipseLinkException(Explanation on the pattern of exceptions in javax.persistence)
EclipseLinkException [message #515675] Fri, 19 February 2010 17:53 Go to next message
Martin Woolstenhulme is currently offline Martin WoolstenhulmeFriend
Messages: 4
Registered: February 2010
Junior Member
EclipseLinkException is the root RuntimeException in the package org.eclipse.persistence.exceptions. This is similar to the manner of PersistenceException in the package javax.persistence. My question is why doesn't EclipseLinkException actually extend javax.persistence.PersistenceException?

In my application I programmed to JPA as specified in Java EE, but when I use the JPA implementation I don't get exceptions that adhere to the specification, they only mimic it. In theory, my application could swap JPA implementations and still work if my application only exposed itself to the Java EE specification.

Specifically, I'm catching the PersistenceException in my source, but the library is throwing EclipseLinkException, so I don't catch it and miss the opportunity to rollback my transaction. The fix is to step up one level and just catch java.lang.RuntimeException, but that adds more generality when I'm only dealing with persistence issues. Otherwise I can catch EclipseLinkException directly and lose some portability. The question isn't critical, but I am curious if someone has perspective on how API implementations map to the API specification.
Re: EclipseLinkException [message #515710 is a reply to message #515675] Fri, 19 February 2010 21:06 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
Hello,

PersistenceException is thrown when using JPA, EclipseLinkExceptions are thrown when using EclipseLink api directly (ie session.executeQuery(query) etc). EclipseLinkException does not extend PersistenceException to avoid having a JPA dependency within the native EclipseLink api.

If your application is using JPA only, you should only be getting javax.persistence.PersistenceExceptions. Can you provide an example where you see an EclipseLinkException from JPA methods?

Best Regards,
Chris

[Updated on: Fri, 19 February 2010 21:08]

Report message to a moderator

Re: EclipseLinkException [message #515719 is a reply to message #515710] Fri, 19 February 2010 22:19 Go to previous messageGo to next message
Martin Woolstenhulme is currently offline Martin WoolstenhulmeFriend
Messages: 4
Registered: February 2010
Junior Member
Thanks Chris,

I used some Entity classes to create an H2 database that were originally developed for Oracle database. Some of the entities Ids used sequences. I let the API recreate the database based on the entities. After I started my application I created new objects for those entities and when I committed the transaction I got the EclipseLinkException because the sequences didn't exist in the new H2 database. Obviously, not creating the sequences was the underlying problem, but the application I wrote didn't handle the exception so my transaction wasn't closed. After I added the sequences from another connection my application state was out of whack and when I tried to begin a new transaction the last one was still open, so I'd get the appropriate IllegalStateException. Restarting the application returned it to a healthy state, but I was curious how that exception escaped my grasp.

If I understand your response correctly, the nonexistent sequences lie outside the scope of a JPA exception, so that's why I got the EclipseLikeException. Or is that any transaction against the database exposes you to underlying JPA implementation?

If you'd still like an example I can provide one.
Re: EclipseLinkException [message #517933 is a reply to message #515719] Tue, 02 March 2010 14:53 Go to previous message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Could you please provide the exception stack trace.


James : Wiki : Book : Blog : Twitter
Previous Topic:Adapting to existing database
Next Topic:Question regarding JPA Joins and predicates
Goto Forum:
  


Current Time: Fri Mar 29 12:31:06 GMT 2024

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

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

Back to the top