关于JPA规范中 EQL 查询的一点建议!
When I use JPA as ORM technology in my project,I have some problem.
Following is my problem.
FROM JPA2.0 SPEC
4.8.2Constructor Expressions in the SELECT Clause
A constructor may be used in the SELECT list to return an instance of a Java class. The specified class is not required to be an entity or to be mapped to the database. The constructor name must be fully qualified.
If an entity class name is specified as the constructor name in the SELECT NEW clause, the resulting entity instances are in the new state.
For example,
SELECT NEW com.acme.example.CustomerDetails(c.id, c.status, o.count)
FROM Customer c JOIN c.orders o
WHERE o.count>100
We can write EQL SQL like that
SELECT NEW com.acme.example.CustomerDetails(c.id, c.status as cdStatus, o.count)
FROM Customer c JOIN c.orders o
WHERE o.count>100
without having appropriate Constructor.(Because in real environment,We should randomly access entity's properties.)
instead,JPA implmentation can invoke the get Mehtod.
(like the native sql
select c.id,c.status as cdStatus,o.count from cust c join order o on(c.id=o.cust_id) where o.count>100 random select clause)
class CustomerDetails
{
private String _id;
private String _status;
private String _count;
public CustomerDetails()
{
}
public void setId(String id)
{
_id = id;
}
public String getId()
{
return _id;
}
public void setCdStatus(String status)
{
_status = status;
}
public String getCdStatus()
{
return _status;
}
public void setCount(String count)
{
_count = count;
}
public String getCount()
{
return _count;
}
}
我曾经发给JSR委员会,没回音,到javaeye上请教高手,我的想法是否可行!