java - QueryDSL 简单查询不会转换为对象

标签 java querydsl

我正在针对 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 的投影只能用于生成的 Bean 类型

最佳答案

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

关于java - QueryDSL 简单查询不会转换为对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11906771/

相关文章:

java - Calendar.getTime() 失败,出现 java.lang.IllegalArgumentException :MINUTE for Asia/Singapore timezone

带有过滤器的 Elasticsearch simple_query_string

mysql - 排序和分页

sql - QueryDSL 中的路径引用连接到子查询

java - 如何从 hashmap 中获取一列值

重新选择文件时 Java JTree 卡住

elasticsearch - ElasticSearch过滤器无法使用must AND must_not

java - 使用 Java Mail 验证带有 Outlook 2013 签名的电子邮件

java - Spring 安全配置 Kotlin DSL