【问题标题】:hibernate projection unique list休眠投影唯一列表
【发布时间】:2014-11-04 16:33:21
【问题描述】:

我正在尝试使用休眠和投影来生成一个没有重复元素的列表。

我有一个 CurrEntityProfileBO 类,它有属性 entityId。

        Criteria criteria = session.createCriteria(
                CurrEntityProfileBO.class, "entityProfileBO");
        criteria.setProjection(Projections.distinct(Projections
    .projectionList().add(Projections.property("entityId"))));

我遇到了一个例外:

[2014-11-04 11:28:59] ERROR [http-8080-5]      (SqlExceptionHelper.java:144) - ORA-01791: not a SELECTed expression

[2014-11-04 11:28:59]  WARN [http-8080-5] (AbstractHandlerExceptionResolver.java:185) - Handler execution resulted in exception
org.hibernate.exception.SQLGrammarException: ORA-01791: not a SELECTed expression

at     org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:82)

感谢任何帮助!

【问题讨论】:

  • criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); 呢?
  • @sp00m 效果很好。你太棒了!!!

标签: java hibernate criteria


【解决方案1】:

根据sp00m。 criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); 效果很好!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-04-11
    • 2013-05-31
    • 2015-07-17
    • 2012-11-26
    • 1970-01-01
    • 1970-01-01
    • 2011-10-12
    • 1970-01-01
    相关资源
    最近更新 更多