我正在尝试运行以下hql但是出现Caused by: java.lang.UnsupportedOperationException: Unrecognized property type: org.hibernate.type.BagType(org.model.Test.groups)
错误。
Query query = session.createQuery("from Test t " +
" JOIN FETCH t.groups g " +
" where t.id=:id" +
" and g.value.name= :name ")
.setString("id", id);
.setString("name", name);
List<Test> tList = query.list();
这个也给出了同样的错误;
Query query = session.createQuery("from Test t " +
" JOIN FETCH t.groups g " +
" JOIN FETCH g.value v " +
" where t.id=:id" +
" and v.name= :name ")
.setString("id", id);
.setString("name", name);
@Entity
@Table
public class Test {
...
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
private List<Group> groups;
...
}
@Entity
@Table
public class Group {
...
@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinColumn(name = "value")
private Value value;
...
}
@Entity
@Table
public class Value {
...
@Column(name="name", nullable=false)
private String name;
...
}
如果我只运行以下hql,我将获得所有测试,组和值表的列值,没有任何问题。
Query q = session.createQuery("from Test t where t.id= :id")
.setString("id", id);
下面是完整的错误堆栈跟踪;
Caused by: java.lang.UnsupportedOperationException: Unrecognized property type: org.hibernate.type.BagType(org.model.Test.groups)
org.hibernate.ogm.query.parsing.impl.ParserPropertyHelper.getPropertyType(ParserPropertyHelper.java:104)
org.hibernate.ogm.datastore.mongodb.query.parsing.impl.MongoDBPropertyHelper.getPropertyType(MongoDBPropertyHelper.java:48)
org.hibernate.ogm.query.parsing.impl.ParserPropertyHelper.convertToPropertyType(ParserPropertyHelper.java:48)
org.hibernate.hql.ast.spi.SingleEntityQueryRendererDelegate.parameterValue(SingleEntityQueryRendererDelegate.java:465)
org.hibernate.hql.ast.spi.SingleEntityQueryRendererDelegate.addComparisonPredicate(SingleEntityQueryRendererDelegate.java:305)
org.hibernate.hql.ast.spi.SingleEntityQueryRendererDelegate.predicateEquals(SingleEntityQueryRendererDelegate.java:284)
org.hibernate.hql.ast.render.QueryRenderer.predicate(QueryRenderer.java:5238)
org.hibernate.hql.ast.render.QueryRenderer.searchCondition(QueryRenderer.java:4912)
org.hibernate.hql.ast.render.QueryRenderer.searchCondition(QueryRenderer.java:4848)
org.hibernate.hql.ast.render.QueryRenderer.whereClause(QueryRenderer.java:2376)
org.hibernate.hql.ast.render.QueryRenderer.querySpec(QueryRenderer.java:2229)
org.hibernate.hql.ast.render.QueryRenderer.queryExpression(QueryRenderer.java:2132)
org.hibernate.hql.ast.render.QueryRenderer.queryStatement(QueryRenderer.java:1771)
org.hibernate.hql.ast.render.QueryRenderer.queryStatementSet(QueryRenderer.java:1684)
org.hibernate.hql.ast.render.QueryRenderer.statement(QueryRenderer.java:680)
org.hibernate.hql.ast.spi.QueryRendererProcessor.process(QueryRendererProcessor.java:51)
org.hibernate.hql.QueryParser.parseQuery(QueryParser.java:82)
org.hibernate.ogm.datastore.mongodb.query.parsing.impl.MongoDBBasedQueryParserService.parseQuery(MongoDBBasedQueryParserService.java:40)
org.hibernate.ogm.query.impl.OgmQueryTranslator.getQuery(OgmQueryTranslator.java:169)
org.hibernate.ogm.query.impl.OgmQueryTranslator.getLoader(OgmQueryTranslator.java:134)
org.hibernate.ogm.query.impl.OgmQueryTranslator.list(OgmQueryTranslator.java:128)
org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:216)
org.hibernate.internal.SessionImpl.list(SessionImpl.java:1339)
org.hibernate.internal.QueryImpl.list(QueryImpl.java:87)
答案 0 :(得分:1)
Hibernate OGM目前不支持在* -to-many关联上使用JOIN进行JP-QL查询:https://docs.jboss.org/hibernate/stable/ogm/reference/en-US/html_single/#_using_jp_ql
答案 1 :(得分:0)
不能说这是否是您特定错误的原因,尤其是因为只有来自entites的部分代码。但请检查一下(因为它抱怨Group
)
您似乎是在Test
&lt;&gt; Group
之间进行双向映射,@OneToMany
注释和List<Group> groups
Test
之后。
Group
如何映射到Test
?没有mappedBy
属性或类似属性。
你应该有类似的东西:
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy="test")
private List<Group> groups;
在Test
方面。在Group
那边你应该有一个像:
@ManyToOne
private Test test;
也许你有但不在提供的代码段中。