【问题标题】:QueryDSL simple query will not cast to objectQueryDSL 简单查询不会转换为对象
【发布时间】:2012-08-10 17:49:06
【问题描述】:

我正在针对 MySql 中的 World 数据库测试 QueryDSL。我可以将数据作为列表检索,但无法将其作为列表返回。我正在通过 SQL 查询,仅此而已。这就是我所拥有的。

private void getSomething(Connection connection) {
  QCountry country = QCountry.country;
  SQLTemplates dialect = new HSQLDBTemplates(); 
  SQLQuery query = new SQLQueryImpl(connection, dialect);

  //List<Object[]> countries = query.from(country).list(country.all());
  List<QCountry> countries = query.from(country).list(country);

  System.out.println(countries);
  try {
    connection.close();
  } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
  }
}

我收到此错误: java.lang.IllegalArgumentException: RelationalPath based projection can only be used with generated Bean types

【问题讨论】:

    标签: java querydsl


    【解决方案1】:

    您需要按照 Bean 类生成http://blog.mysema.com/2011/01/querying-in-sql-with-querydsl.html 的说明生成 bean 类型。

    【讨论】:

      猜你喜欢
      • 2015-10-21
      • 1970-01-01
      • 2021-07-15
      • 1970-01-01
      • 2013-08-29
      • 2018-10-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多