Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » JPA2: how access entity name for projection query
JPA2: how access entity name for projection query [message #712447] Sun, 07 August 2011 08:55 Go to next message
darren is currently offline darrenFriend
Messages: 19
Registered: March 2011
Location: Sydney, Australia
Junior Member
By entity name I mean the value of the name attribute of the @Entity annotation, which defaults to the simple class name of the entity class.

The information is there in the database form of a DTYPE column - I am using a "supertable" @Inheritance(strategy=InheritanceType.JOINED) - but I don't know how to expose this information in a projection query.

grateful for suggestions,

Webel IT Australia

[Updated on: Sun, 07 August 2011 08:56]

Report message to a moderator

Re: JPA2: how access entity name for projection query [message #713504 is a reply to message #712447] Mon, 08 August 2011 14:49 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

The TYPE() function should work.


James : Wiki : Book : Blog : Twitter
Re: JPA2: how access entity name for projection query [message #713747 is a reply to message #713504] Tue, 09 August 2011 00:23 Go to previous messageGo to next message
darren is currently offline darrenFriend
Messages: 19
Registered: March 2011
Location: Sydney, Australia
Junior Member
@james

Quote:
The TYPE() function should work.


This contradicts the experience reported at http://www.eclipse.org/forums/index.php/m/713742/#msg_713742

If I use a String argument in the constructor expression to receive what you suggest would be the entity name, it fails and requires a java.lang.Class.
Re: JPA2: how access entity name for projection query [message #713751 is a reply to message #713747] Tue, 09 August 2011 00:41 Go to previous messageGo to next message
darren is currently offline darrenFriend
Messages: 19
Registered: March 2011
Location: Sydney, Australia
Junior Member
I don't want to confuse matters with 2 parallel message threads here, but they are in fact asking separate things.

This thread is asking how to access the entity name for a projection query, and James has suggested that TYPE() does return the entity name, and that would seem to agree with this example from Pro JPA2 p.262:

SELECT p.name, CASE WHEN TYPE(p) = DesignProject THEN 'Development' ..


Here 'DesignProeject' is clearly an entity name.

But a constructor expression to accept a TYPE() using a String fails with a request for a java.lang.Class. So I am not convinced that TYPE() in the context of a projection query result is returning the entity name.

The thread at: http://www.eclipse.org/forums/index.php/mv/msg/233012/712438/#msg_712438 (TYPE() fails in projection query result: EclipseLink ConversionException) is specifically asking about the use of TYPE() in a projection query, where it was intended to elicit the fully qualified class, not the entity name.

I in fact need both the entity name and the fully qualified class.

If I have one (from an entity query) I can always find the other outside the query result, by examining the metamodel (once at application startup then caching map of entity name to entity class, or vice versa).

But as it stands I can currently access neither entity name nor entity class.




Re: JPA2: how access entity name for projection query [message #713754 is a reply to message #713751] Tue, 09 August 2011 01:05 Go to previous message
darren is currently offline darrenFriend
Messages: 19
Registered: March 2011
Location: Sydney, Australia
Junior Member
On use of type() in criteria API: http://www.eclipse.org/forums/index.php/m/713753/#msg_713753
Previous Topic:uses a non-entity as target entity in the relationship attribute
Next Topic:java.lang.NoSuchMethodError: xxx._persistence_checkFetched(Ljava/lang/String;)V
Goto Forum:
  


Current Time: Sat Nov 22 21:34:37 GMT 2014

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

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