30 Mai 2008

Missing features in JPA

During the past JPA course at the university of applied sciences in Bern I discovered two missing features in JPA:

1. static inner classes in constructor expressions

Example:


// Constructor Expression
String queryString =
"SELECT NEW Outer.Inner(e.name) FROM Employee e";

Query query = em.createQuery(queryString);
List outer = query.getResultList();
for (Outer.Inner inner : outer) {
...
}

Where Outer.Inner is a static inner class in Outer:


public class Outer {
public static class Inner {
private String name;
public Inner(String name) {
this.name = name;
}
public String getName() {
return this.name;
}
}
}

In my opinion this should work. Because I can instanceiate Inner like this:
Outer.Inner in = new
Outer.Inner("Simon");

2. Enumerations in JPQL

For example, this works fine:

String queryString =
"SELECT a FROM Address a where a.addressType = :type";

Query query = em.createQuery(queryString);
query.setParameter("type", AddressType.OFFICE);

But this does not:

String queryString = "SELECT a FROM Address a where a.addressType = AddressType.OFFICE";
Query query = em.createQuery(queryString);

Surprising this works in Hibernate but not with TopLink:

String queryString = "SELECT a FROM Address a where a.addressType = 'OFFICE'";
Query query = em.createQuery(queryString);

I hope this two features will be contained in the next JPA relase!

Kommentare:

Mike hat gesagt…

Simon,

The classloading context of the execution is not known beforehand, hence when specifying classes in JP QL you must fully qualify the class names. I don't see that as a missing feature, but simply as a reality :-).

If you were to fully qualify the enum type constant then the example you listed would work in TopLink as well.

Simon Martinelli hat gesagt…

Hi Mike,

For sure your absolutely right!

Thanks for your comment!

Anonym hat gesagt…

I found this site using [url=http://google.com]google.com[/url] And i want to thank you for your work. You have done really very good site. Great work, great site! Thank you!

Sorry for offtopic

Anonym hat gesagt…

Who knows where to download XRumer 5.0 Palladium?
Help, please. All recommend this program to effectively advertise on the Internet, this is the best program!