简体   繁体   中英

QueryDSL simple query will not cast to object

I am testing QueryDSL against the World database in MySql. I can retrieve the data as a List, but I cannot get it to return as a List. I am querying via SQL, nothing else. This is what I have.

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();
  }
}

I get this error: java.lang.IllegalArgumentException: RelationalPath based projection can only be used with generated Bean types

您需要生成bean类型,如此处所述http://blog.mysema.com/2011/01/querying-in-sql-with-querydsl.htmlBean类生成下

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM