[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-5348?page=c...
]
Anwar Rizal commented on HHH-5348:
----------------------------------
The following code (with ItemNameDescription.java in the attachment) uncovers the
problem:
public void testSelectProjectiveQuery() {
Item item = new Item( "ItemName", "ItemDescription" );
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist(item);
em.getTransaction().commit();
TypedQuery<ItemNameDescription> q = em.createQuery(
"SELECT new org.hibernate.ejb.test.ItemNameDescription(it.name, it.descr) FROM
Item it",
ItemNameDescription.class);
List<ItemNameDescription> result = q.getResultList();
assertEquals(1, result.size());
assertEquals("ItemName", result.get(0).getName());
assertEquals("ItemDescription", result.get(0).getDescr());
em.close();
}
The exception is thrown in AbstractEntityManagerImpl class:
org.hibernate.Query hqlQuery = getSession().createQuery( jpaqlString );
if ( hqlQuery.getReturnTypes().length != 1 ) {
throw new IllegalArgumentException( "Cannot create TypedQuery for query with more
than one return" );
}
hqlQuery.getReturnTypes() return array of string instead of ItemNameDescription. After
debugging a little bit, I think the problem is on HQLQueryPlan class that does not build
the return type correctly.
Best regards,
Anwar.
java.lang.IllegalArgumentException: Cannot create TypedQuery for
query with more than one return with AbstractEntityManager.createQuery(String jpaqlString,
Class<T> resultClass) on View object
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Key: HHH-5348
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-5348
Project: Hibernate Core
Issue Type: Bug
Components: entity-manager
Affects Versions: 3.5.3
Reporter: nodje
Attachments: ItemNameDescription.java
I'm getting a
java.lang.IllegalArgumentException: Cannot create TypedQuery for query with more than one
return
with a query that returns a View object.
AbstractEntityManager:279, detects as many returns type as there is parameters in the
View object, instead of one single result type, the View Object itself.
QueryString example that fails with public <T> TypedQuery<T>
createQuery(String jpaqlString, Class<T> resultClass):
"select new WorkContractDto(wc.workContractStartDate, wc.workContractEndDate,
wc.workContractEmployeeLastName, wc.workContractSendingStatus) from WorkContract wc where
wc.workContractEmployeeLastName = ?1"
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira