简体   繁体   English

找不到JPA构造函数类[Emp]-oracle.toplink.essentials.exceptions.EJBQLException

[英]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 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. SELECT列表中可以使用构造函数来返回一个或多个Java实例。 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 在namedQuery中而不是

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

provide fully qualified class name, ie <packagename>.<classname> 提供完全限定的类名,即<packagename>.<classname>

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

Thanks. 谢谢。

Courtesy 礼貌

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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