Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Order by primary key as a associated entity.
Order by primary key as a associated entity. [message #769597] Thu, 22 December 2011 11:49 Go to next message
Radek Hodain is currently offline Radek Hodain
Messages: 16
Registered: February 2010
Junior Member
Hi,

I have a question about ordering in JPA using EclipseLink. JPA 2.0 allows to define @Id to associated entity (as derived identity).

So I have entities like these:

@Table(name = "entity")
public class Entity {

.....
@Id
@ManyToOne()
@JoinColumn(name = "AE_ID")
private AssociatedEntity associated;

.....
}

@Table(name = "associated")
public class AssociatedEntity {

.....
@Id
@Column(name = "AE_ID")
private String code;
.....
}

Hibernate allows to use simething like this:

SELECT entity FROM ENTITY AS entity ORDER BY entity

which creates SQL like:

SELECT .... FROM entity t0 ORDER BY t0.AE_ID"

We know that JPA specification says that ORDER BY item must be a state_field_path_expression. Is in EclipseLink any posibility how to do the same (some hint or implementation specific resolution)?

Thanks

Radek
Re: Order by primary key as a associated entity. [message #769760 is a reply to message #769597] Thu, 22 December 2011 16:35 Go to previous messageGo to next message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

I do not think it is support, you could consider logging a bug or enhancement.

You could double map the relationship as a Basic as well to order by the id.
With EclipseLink you can also define a QueryKey for any column using a DescriptorCustomizer and use the query key with JPQL.



James : Wiki : Book : Blog : Twitter
Re: Order by primary key as a associated entity. [message #769762 is a reply to message #769597] Thu, 22 December 2011 16:35 Go to previous messageGo to next message
James is currently offline James
Messages: 272
Registered: July 2009
Senior Member
I do not think it is support, you could consider logging a bug or enhancement.

You could double map the relationship as a Basic as well to order by the id.
With EclipseLink you can also define a QueryKey for any column using a DescriptorCustomizer and use the query key with JPQL.


--
James : http://wiki.eclipse.org/EclipseLink : http://en.wikibooks.org/wiki/Java_Persistence : http://java-persistence-performance.blogspot.com/
Re: Order by primary key as a associated entity. [message #774652 is a reply to message #769762] Wed, 04 January 2012 10:46 Go to previous messageGo to next message
Radek Hodain is currently offline Radek Hodain
Messages: 16
Registered: February 2010
Junior Member
Hi,

first, thank you for your replay. I've tryed both your suggestions.

1) "You could double map the relationship as a Basic as well to order by the id"

Did you mean something like this?

...

@Id
@ManyToOne(optional = false, fetch = FetchType.LAZY)
@JoinColumn(name = "id_asoc")
private Asoc asoc;

@Column
private Long asocId;

...

If I do this I get problem with metadata. I expect that the method getIdClassAttributes get me asoc attribute but instead of it get me asocId. I've found that org.eclipse.persistence.internal.descriptorsObjectBuilder in the method initializePrimaryKey changes it. I don't know if it is correct.

final EntityType<? extends Object> entityType = entityManager.getMetamodel().entity(entityClass);
final Set<SingularAttribute> idClassAttributes = (Set) entityType.getIdClassAttributes();

2) "With EclipseLink you can also define a QueryKey for any column using a DescriptorCustomizer and use the query key with JPQL."

I need to build query by criteria API. Is there any posibilities hot to use query key with criteria API?
Re: Order by primary key as a associated entity. [message #777500 is a reply to message #774652] Tue, 10 January 2012 15:55 Go to previous message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

For 1) you should use the same column

@Column(name="id_asoc", insertable=false, updateable=false)
private Long asocId;

For 2)
Yes you can use a query key with criteria.


James : Wiki : Book : Blog : Twitter
Previous Topic:Where to define schema?
Next Topic:Erroneously duplicated @DiscriminatorValue - don't try this at home
Goto Forum:
  


Current Time: Thu Oct 02 10:37:06 GMT 2014

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

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