简体   繁体   中英

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

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.

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)

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, ie <packagename>.<classname>

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

Thanks.

Courtesy

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM