我正在尝试使用WHERE子句中的ID从数据库中检索USER。但是,我收到一个错误,我的程序失败了。
这是我在运行程序时收到的错误:
ERROR [org.jboss.as.ejb3.invocation] (default task-19)
JBAS014134: EJB Invocation failed on component CustomerServiceBeanImpl
for method public abstract package.name.entity.ICustomer
package.name.bean.CustomerServiceBean.getCustomerById(long):
javax.ejb.EJBException: java.lang.IllegalArgumentException:
Parameter value [19533] did not match expected type [package.name.entity.User (n/a)]
注意:[19533]是我使用的测试值。
这是在CustomerServiceBeanImpl.java中出错的方法:
@Override
public Customer getCustomerById (final long id)
{
return Customer.getById (this.em, id);
}
这是组件CustomerServiceBeanImpl所调用的方法:
public static Customer getById (final EntityManager em, final long id)
{
for (final Customer c : em.createNamedQuery ("Customer.getById", Customer.class)
.setParameter ("id", id).setMaxResults (1).getResultList ())
{
return c;
}
return null;
}
名称查询是这样的:
@NamedQuery (name = "Customer.getById",
query = "SELECT o FROM gnf.Customer o WHERE o.user = :id")
在Customer.java类本身中,相关列是这一列:
@ManyToOne (fetch = FetchType.LAZY)
@JoinColumn (name = "user_id")
private User user;
快速检查我的ERD,“客户”表中的“ id”列的数据类型为BIGINT。但是我不确定这是否重要。(顺便说一下,PostgreSQL数据库。)
如何解决此错误?
您的命名查询中的WHERE子句似乎是问题所在。Customer.class中的属性user是User类型,您的查询希望它是与long兼容的类型。
...参数值[19533]与预期的类型[package.name.entity.User ...不匹配...
因此,如果您需要更多帮助,最好查看完整的用户实体和客户实体。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句