java.lang.IllegalArgumentException

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • 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.
    via by Bjorn Beskow,
  • 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.
    via by Bjorn Beskow,
  • How to pass parameter on jpa query?
    via Stack Overflow by Yubaraj
    ,
    • 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)

    Users with the same issue

    Unknown visitor1 times, last one,