I'm trying to make a JPQL query that should fetch an entity and the keys from one of its map associations, and I'm getting a bizzare error.
My setup is JPA2 using the Hibernate (3.5) implementation.
The model is as follows:
I have a Department entity bean such as:
@Entity
public class Department {
@Id
@SequenceGenerator(name = "DEPARTMENT_ID_GENERATOR", sequenceName="department_sequence", allocationSize=100)
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator = "DEPARTMENT_ID_GENERATOR")
@Column(unique = true, nullable = false)
protected Long id;
@OneToMany(fetch=FetchType.EAGER)
private Map<String,Phone> phones = new HashMap<String, Phone>();
//... getters and setters follow
and it's associated entity :
@Entity
public class Phone {
@Id
@SequenceGenerator(name = "PHONE_ID_GENERATOR", sequenceName="phone_sequence", allocationSize=100)
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator = "PHONE_ID_GENERATOR")
@Column(unique = true, nullable = false)
protected Long id;
private int number;
//... getters and setters follow
Now I thought, as per the "Mastering JPA2..." book, that I could do a JPQL such as:
String queryString2 = "SELECT d, KEY(p) FROM Department d JOIN d.phones p WHERE p='internal'";
but all this gets me a bizzare error:
java.lang.IllegalStateException: No data type for node: org.hibernate.hql.ast.tree.MethodNode
-[METHOD_CALL] MethodNode: '(' +-[METHOD_NAME] IdentNode: 'KEY' {originalText=KEY} -[EXPR_LIST] SqlNode: 'exprList' -[ALIAS_REF] IdentNode: 'phone2_.id' {alias=p, className=model.Phone, tableAlias=phone2_}
at org.hibernate.hql.ast.tree.SelectClause.initializeExplicitSelectClause(SelectClause.java:156)...
Can someone please tell me if the JPQ I'm using is wrong, and if so, what might be a correct alternative to getting an entity and ONLY the keys from one of its map associations?
对于下一个读者,Mikko Maunu提到的bug昨天刚刚解决,所以我们只需要等待下一个版本:)
你的语法是正确的,这是因为没有实现地图的KEY&VALUE: https : //hibernate.onjira.com/browse/HHH-5396我不知道其他查询。
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.