[hibernate-issues] [Hibernate-JIRA] Created: (EJB-384) JPQL Constructor Queries containing Timestamp cause exception

Bjorn Beskow (JIRA) noreply at atlassian.com
Wed Sep 24 07:55:04 EDT 2008


JPQL Constructor Queries containing Timestamp cause exception
-------------------------------------------------------------

                 Key: EJB-384
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/EJB-384
             Project: Hibernate Entity Manager
          Issue Type: Bug
    Affects Versions: 3.3.1.GA
         Environment: Hibernate 3.3.1.GA, Derby, JDK1.5, Windows.
            Reporter: Bjorn Beskow
            Priority: Minor
         Attachments: hibernate-jpql-timestamp-bug.zip

When a constructor JPQL query projects a Timestamp, it causes an org.hibernate.hql.ast.QuerySyntaxException: Unable to locate appropriate constructor.

For example, given the following Entity:

@Entity
public class Employee {
    ...
    private Timestamp lastUpdatedAsTimestamp;
    ...
}

and the following Pojo for the constructor query:

    public EmployeeDto(String name, Timestamp lastUpdated) {...}

the following query will throw an exception:

    	String query =
    		"SELECT new test.dto.EmployeeDtoUsingTimestamp(e.name, e.lastUpdatedAsTimestamp) " +
          	"FROM Employee e ORDER BY e.name";

    	List<EmployeeDto> reportList = em.createQuery(query).getResultList();

java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: Unable to locate appropriate constructor on class [test.dto.EmployeeDto] [SELECT new test.dto.EmployeeDto(e.name, e.lastUpdated) FROM test.entities.Employee e ORDER BY e.name]
	at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:601)
	at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:96)
	at test.ConstructorQueryTest.testEmployeesQuery(ConstructorQueryTest.java:63)
    ...

This problem has been reported before (see HHH-278), but the workaround is not a portable JPA solution (having the type Timestamp in the Entity and the type Date in the Pojo constructor is not in line with the Spec, and does not work in other JPA implementations).

I have attached a minimal Maven project with a test case which highlights the problem.


-- 
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.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list