Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » bizar?
bizar? [message #491436] Wed, 14 October 2009 14:58 Go to next message
Tom Eugelink is currently offline Tom EugelinkFriend
Messages: 817
Registered: July 2009
Senior Member
I'm mind blocked at the moment; if I start my Swing application from Eclipse using weaving and execute this call:

lQuery = lEntityManager.createNativeQuery("select batchnr from batch ...");
lQuery.getResultList())

A List<NonSynchronizedVector> is returned. If the same code is executed at runtime using a preweaved jar, a List<Integer> is returned.

How should I treat this? Why the NonSynchronizedVector? I really would have like to get something similar returned, not an Integer vs a Vector...

Tom
native query getResultList; NonSynchronizedVector [message #492169 is a reply to message #491436] Mon, 19 October 2009 09:05 Go to previous messageGo to next message
Tom Eugelink is currently offline Tom EugelinkFriend
Messages: 817
Registered: July 2009
Senior Member
I wrote an sanitize function to make sure the weaving and preweaving getResultList of a native query can be handled uniformly.



/**
* A native query returns a different result when executed in weaving mode (-javaagent) vs preweaved mode.
* In weaving mode a list of NonSynchronizedVectors is returned, where the vector contains the actual values.
* List<NonSynchronixedVector<Object>>
* In preweaved mode depending on the number of fields queried, either a list of values is returned, or a list of arrays where the array contains the actual values.
* List<Object>
* List<Array<Object>>
*
* In order to make sure the code only has to deal with one scenario, this method sanitizes the result to the preweaved structure (eliminating NonSynchronizedVector).
* For a single field query:
* for (Number lNumber : (List<Number>)JpaUtil.sanatizeNativeQueryResult(lQuery.getResultList()))
* {
* ...
*
* For a multiple field query:
* for (Object[] lValues : (List<Object[]>)JpaUtil.sanatizeNativeQueryResult(lQuery.getResultList()))
* {
* BigInteger lNr = new BigInteger(lValues[0].toString());
* String lName = (String)lValues[1];
* ...
*
* The user needs to know what the return value will be.
*
* @param return value of getResultList() on a native query
* @return List<Object> if one field is queried, List<Array<Object>> is multiple fields are queried.
*/
static public List sanitizeNativeQueryResult(List l)
{
// quick exits
if (l == null || l.size() == 0) return l;

// the result, assume we return what we got
List lResult = l;

// if he list contains NonSynchronizedVector
if ((l.get(0) instanceof NonSynchronizedVector))
{
// we start a new list
lResult = new ArrayList();
for (Object lObject : l)
{
NonSynchronizedVector lNonSynchronizedVector = (NonSynchronizedVector)lObject;
// a single results is added directly
if (lNonSynchronizedVector.size() == 1) lResult.add( lNonSynchronizedVector.get(0) );
// multiple results are added as an array
else lResult.add( lNonSynchronizedVector.toArray() );
}
}

// done
return lResult;
}
Re: bizar? [message #492238 is a reply to message #491436] Mon, 19 October 2009 14:46 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

I can't see how this could occur, or how weaving could have anything to do with it. Weaving has no effect of native queries.

It seems that you are getting either a different EclipseLink version, or another JPA provider in one case.

EclipseLink should return List<Integer> never List<Vector>. The was a bug in EclipseLink 1.0 that a Vector could be returned, but this was fixed.


James : Wiki : Book : Blog : Twitter
Re: bizar? [message #492261 is a reply to message #492238] Mon, 19 October 2009 15:59 Go to previous messageGo to next message
Tom Eugelink is currently offline Tom EugelinkFriend
Messages: 817
Registered: July 2009
Senior Member
I'm not using 1.0, but so of the top of my head a 1.1.2 or something. And all I can say is that I needed to write code to compensate for the NonSynchronizedVector; I did not invent that.

I will write a small test; it should be trivial.
Re: bizar? [message #492360 is a reply to message #492261] Tue, 20 October 2009 08:10 Go to previous message
Tom Eugelink is currently offline Tom EugelinkFriend
Messages: 817
Registered: July 2009
Senior Member
> I will write a small test; it should be trivial.

Often the ease with which Eclipse uses and prioritizes jars in other projects causes confusion; one of the underlying Util projects had an Eclipselink 1.0.2, because it holds an EclipselinkUtil class.

I posted a request on the Eclipse IDE forum asking if a different include behavior can be configured, because this is way too automagical for me and not the way normal JARs work.
http://www.eclipse.org/forums/index.php?t=msg&goto=49235 6&S=f06fc5ee285552e03bdcf187bbd76f44#msg_492356
Previous Topic:be able to specify JDBC driver jar w/o adding it to manifest
Next Topic:Eclipselink with Apache Felix
Goto Forum:
  


Current Time: Fri Apr 19 19:14:20 GMT 2024

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

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

Back to the top