Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Unmapped Columns in ResultSet
Unmapped Columns in ResultSet [message #1320177] Mon, 28 April 2014 16:37 Go to next message
Scott Dudley is currently offline Scott DudleyFriend
Messages: 21
Registered: October 2012
Junior Member
Although I've been using Eclipselink JPA for over a year now, I'm still little more than a neophyte.

Last year I replaced our 14 year-old, home-grown ORM layer with JPA. We had a legacy feature that I'd like to replicate in the JPA Entity but not clear on how to go about it.

Is is somewhat akin to "flex fields" and in other regards, not so much.

Essentially, my native query includes columns for which there are no Entity fields/mappings. What I'd like to do is have these automatically inserted into a key/value map on the Entity when the Entity is constructed from the ResultSet.

Any ideas on how best to go about it?

Thanks.
Re: Unmapped Columns in ResultSet [message #1320287 is a reply to message #1320177] Mon, 28 April 2014 18:04 Go to previous messageGo to next message
Shaun Smith is currently offline Shaun SmithFriend
Messages: 197
Registered: July 2009
Senior Member
Hi Scott,

Take a look at Extensible Entities. This feature let's you augment an entity with additional metadata defined attributes.

--Shaun

Re: Unmapped Columns in ResultSet [message #1320529 is a reply to message #1320287] Mon, 28 April 2014 21:16 Go to previous messageGo to next message
Scott Dudley is currently offline Scott DudleyFriend
Messages: 21
Registered: October 2012
Junior Member

Shaun,

Just read the link you provided and I like the functionality however, due to the nature of this legacy feature, the metadata is unknown until the time at which the native query is executed.

The home-grown ORM just placed all ResultSet values for which there was no direct mapping into a map where the values were available for subsequent access. This was done in our equivalent to getResultList().

Is there any way to do the same with JPA?
Re: Unmapped Columns in ResultSet [message #1322393 is a reply to message #1320529] Tue, 29 April 2014 20:56 Go to previous messageGo to next message
Shaun Smith is currently offline Shaun SmithFriend
Messages: 197
Registered: July 2009
Senior Member
There's no easy solution for this because EclipseLink with caching and cloning depends on a stable mapping between object and table and knowing what fields are persisted. Do you just want to read data into POJOs or do you have to read entities?

--Shaun
Re: Unmapped Columns in ResultSet [message #1322459 is a reply to message #1322393] Tue, 29 April 2014 21:42 Go to previous messageGo to next message
Scott Dudley is currently offline Scott DudleyFriend
Messages: 21
Registered: October 2012
Junior Member

These are Entities Shaun.

The data really is equivalent to flex fields but reside in a relational format that doesn't lend itself easily to mapping via the standard JPA approaches.

Since it's legacy and there's a lot of old code leaning on it, don't want to touch it. That's why it was easiest with the old ORM to simply place these columns from the ResultSet in a Map.

In the last 24 hours, I've devoured the documentation - read up on Dynamic and Extensible entities for which neither are a good fit. I stumbled upon the query redirector and toyed with same but quickly discovered that it really didn't facilitate access to a builder where I'd have iterative access to both ReslultSet and the constructed Entity.

Sounds simple - I just don't see a path.
Re: Unmapped Columns in ResultSet [message #1322467 is a reply to message #1322459] Tue, 29 April 2014 21:48 Go to previous messageGo to next message
Scott Dudley is currently offline Scott DudleyFriend
Messages: 21
Registered: October 2012
Junior Member
Oh, and I failed to address one of your questions: I don't want to persist these values from the Entity. They're transient and read-only.

In the last year, this is the first and only show-stopper I've encountered augmenting functionality from the old, home-grown ORM with JPA. To say that Eclipselink is very robust and feature-rich would be a gross understatement.

Thanks for your time and appreciate any ideas.
Re: Unmapped Columns in ResultSet [message #1325960 is a reply to message #1322467] Thu, 01 May 2014 13:36 Go to previous messageGo to next message
Shaun Smith is currently offline Shaun SmithFriend
Messages: 197
Registered: July 2009
Senior Member
I think you're going down the paths I would explore. Marking the query results as read only and maybe even setting the cache retrieve mode to BYPASS should avoid the cloning issue. One possible approach is to look at a postBuild DescriptorEventListener that you would configure in a Customizer. Subclass DescriptorEventAdaptor and just override the postBuild. Through the passed DescriptorEvent parameter you should have access to the read row (Record). At this point you could examine the Descriptor to figure out what read columns are mapped and which ones you need to put into your Map. FYI, you can attach properties to Descriptors so you could cache this information so you don't have to calculate it every time.

Hope this helps!

--Shaun
Re: Unmapped Columns in ResultSet [message #1326173 is a reply to message #1325960] Thu, 01 May 2014 16:04 Go to previous messageGo to next message
Scott Dudley is currently offline Scott DudleyFriend
Messages: 21
Registered: October 2012
Junior Member
Shaun,

I already have a customizer postBuild method so I coded a little test and enumerated the contents of getRecord().

Oddly, the column names for these extraneous columns are not present in the keyset however, the values are.

Why would those column names not propagate from the JDBC ResultSetMetaData to the keyset?

Thanks.
Re: Unmapped Columns in ResultSet [message #1328092 is a reply to message #1326173] Fri, 02 May 2014 14:01 Go to previous messageGo to next message
Shaun Smith is currently offline Shaun SmithFriend
Messages: 197
Registered: July 2009
Senior Member
I'd assume it's because EclipseLink has no knowledge of the column names because they aren't mapped to fields. With native SQL queries, the SQL is passed directly to the database and isn't parsed by EclipseLink. What are the keys in the Record for the unmapped columns?

BTW, here's a blog post on a somewhat related topic in which I use a redirector and process the query results myself. I thought it might be helpful: http://onpersistence.blogspot.ca/2010/07/eclipselink-jpa-native-constructor.html

--Shaun
Re: Unmapped Columns in ResultSet [message #1328909 is a reply to message #1328092] Fri, 02 May 2014 23:17 Go to previous message
Scott Dudley is currently offline Scott DudleyFriend
Messages: 21
Registered: October 2012
Junior Member
The Record keys for the unmapped columns are null. The keyset entries are blank but the toString method on the Record reveals them to be null.
Previous Topic:Problem removing directory with database
Next Topic:@TableGenerator - Pre-allocate ID block not work fine [SOLVED]
Goto Forum:
  


Current Time: Fri Apr 19 22:11:07 GMT 2024

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

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

Back to the top