【发布时间】:2017-09-21 03:33:04
【问题描述】:
我有这样的情况, 如果有人可以帮助我解决问题,那就太好了。
@MappedSuperclass
public abstract class AbstractEntity implements Serializable, Cloneable {
private int id;
}
public class A extends AbstractEntity{ //Both A and B Entities will store in Table A in Database(in the same table)
//some code
}
public class B extends A{
//some fields
}
public class C extends AbstractEntity{ //Data will be Store in Table C in database and there's a column name b_id as integer to hold the id of Entity b
B b;
}
现在我的 NamedQuery 中有这样一个查询
query="SELECT e FROM C e WHERE e.b= :vid"
//int vid;
问题是 JPA 抛出异常,因为 'b' 是 'B' 的类类型 var 而 'vid' 是 Integer var。
我不能说,
query="SELECT e FROM C e WHERE e.b.id= :vid"
因为 'b' 扩展了 'A' 而 'A' 扩展了 AbstractEntity,这就是我的想法,因为我尝试过并得到了一些错误'参数值 [601] 与预期类型不匹配' //601 是 id数据库中表“A”中的实体。
【问题讨论】:
-
AbstractEntity中的私有成员id不会被继承到类B -
我将其更改为受保护但它给了我'没有实体的默认构造函数'错误@alayor
标签: java jpa hql jpql named-query