JPA constructor class [Emp] not found - oracle.toplink.essentials.exceptions.EJBQLException

241 views Asked by At

This is in continuation of this question

I have namedQuery as

select new Emp(o.empNo, o.empName)  from Emp o

and constructor defined as

public Emp(String empNo, String empName) {
    this.empNo= empNo;
    this.empName= empName;
}

I am getting error when I execute

Exception [TOPLINK-8013] (Oracle TopLink Essentials - 2.1 
(Build b52-fcs (09/24/2008))):
oracle.toplink.essentials.exceptions.EJBQLException
Exception Description: Error compiling the query [Emp.findAll:
select new Emp(o.empNo, o.empName)  from Emp o ], line 1, column 9: 
constructor class [Emp] not found.
2

There are 2 answers

0
Adrian B. On BEST ANSWER

http://openjpa.apache.org/builds/1.2.0/apache-openjpa-1.2.0/docs/manual/jpa_langref.html#jpa_langref_constructor

A constructor may be used in the SELECT list to return one or more Java instances. The specified class is not required to be an entity or to be mapped to the database. The constructor name must be fully qualified.

SELECT NEW com.company.PublisherInfo(pub.id, pub.revenue, mag.price)
2
Jacob On

I have managed to resolve the error, might be useful for others.

In namedQuery instead of

select new Emp(o.empNo, o.empName)  from Emp o

provide fully qualified class name, i.e. <packagename>.<classname>

select new test.entity.Emp(o.empNo, o.empName) from Emp o

Thanks.

Courtesy