QueryDSL简单查询不会强制转换为对象

时间:2012-08-10 17:49:06

标签: java querydsl

我在MySql中对World数据库测试QueryDSL。我可以将数据检索为List,但我无法将其作为List返回。我通过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

1 个答案:

答案 0 :(得分:2)

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