openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Will Hoover" <>
Subject RE: OpenJPA + Native Query = Meta Data
Date Mon, 28 Jan 2013 19:32:22 GMT
Hey Kevin,
I figured out what the cause IllegalStateException was. I'm using Spring +
Atomikos for my transaction management and forgot to annotate my Service
class with @Transactional (had it on my method, but needed it on my class).
Sorry for the noise on that one!

The other issue seems to be related to how OpenJPA determines when to
activate the tooling behind the "openjpa.jdbc.SynchronizeMappings" option.
Even though the property is omitted from my persistence.xml OpenJPA still
seems to want to execute it when I try to
"entityManager.unwrap(java.sql.Connection.class)". Because of this issue I
tried to troubleshoot the problem by creating a new entity manager from the
current entity manager's factory and then extract the connection, but never
intended to permanently use it. Could this potentially be a bug?

Unfortunately, I was running it through a junit test when I encountered the

-----Original Message-----
From: Kevin Sutter [] 
Sent: Monday, January 28, 2013 12:54 PM
Subject: Re: OpenJPA + Native Query = Meta Data

Hi Will,
Accessing the Connection directly should also be a possibility.  Not sure
about the exceptions you are getting though.  The IllegalStateException
sounds like you might be requesting a Connection when a Connection doesn't
exist.  What ConnectionRetainMode value are you using?  Maybe you need to
hold onto your Connections longer (ie. transaction scoped) to satisfy this
extra processing you are looking to do.

The other path you describe sounds convoluted when creating a new EM just to
get access to a Connection.  It looks like OpenJPA is getting confused going
through this path and is accidentally calling into the synchronize mappings

If you could help isolate the issues with simple junit test cases, it would
be much easier to debug.

Good luck,

On Mon, Jan 28, 2013 at 9:49 AM, Will Hoover <> wrote:

> Thanks for the suggestions Kevin! I'd like to stay clear of listeners 
> if I can so I can keep it localized to the handful of use cases where 
> I actually need it :/
> I'm not sure if this is the best solution or not, but I seem to be 
> running out of practical solutions that will keep metadata isolated. I 
> figured that in this case I'm already using a native query. So, why 
> not just capture the connection from the entity manager and create the 
> native statement that will allow access to the metadata. The only 
> problem is the
> entityManager.unwrap(java.sql.Connection.class) seems to be unpredictable.
> Sometimes I receive "java.lang.IllegalStateException: No transactional 
> EntityManager available" and
> entityManager.getEntityManagerFactory().createEntityManager().unwrap(j
> ava.sq
> l.Connection.class) likes to call "synchronizeMappings" in 
> JDBCBrokerFactory#newBrokerImpl(String user, String pass) even though 
> the OpenJPA documentation (version 2.2.1) indicates that the lack of 
> "openjpa.jdbc.SynchronizeMappings" will prevent such a call. Maybe I'm 
> missing something here?
> -----Original Message-----
> From: Kevin Sutter []
> Sent: Thursday, January 24, 2013 9:34 AM
> To:
> Subject: Re: OpenJPA + Native Query = Meta Data
> Not that I am aware of...  Of course, OpenJPA has access to and 
> utilizes the metadata while processing the result set, but I don't see 
> a means of providing that metadata back to the application.  Since 
> OpenJPA is open-source, we always welcome new feature submissions...  
> :-)
> One alternative that might work for you is to tie into OpenJPA's JDBC 
> Listeners [1].  If you tied into the post execute statement listener, 
> you could get access to the jdbc-related artifacts and do your own 
> parsing of the information.  Maybe not quite as easy as the 
> eclipselink feature, but would that provide the metadata you are looking
> Kevin
> [1]
> T/docs/docbook/manual.html#openjpa.jdbc.JDBCListeners<http://people.ap
> s/docbook/manual.html#openjpa.jdbc.JDBCListeners>
> On Tue, Jan 22, 2013 at 2:11 PM, Will Hoover <>
> wrote:
> > Is there any feature in OpenJPA that will allow capture of a queries 
> > metadata (similar to "eclipselink.result-type"="Map")?
> >
> >
> >
> > I'm trying to capture a rowid from a native query update call.
> >
> >
> >
> >
> >
> >

View raw message