将SQL(不是JPQL)映射到简单Java对象的集合吗? [英] Map SQL (not JPQL) to a collection of simple Java objects?

查看:83
本文介绍了将SQL(不是JPQL)映射到简单Java对象的集合吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不敢相信我在问这个,但是...

I can't believe I'm asking this, but...

在Java中,有什么方法可以执行SQL语句(不是JPQL)并将结果映射到普通Java对象的List?

Is there any way, in Java, to execute a SQL statement (not JPQL) and map the results to a List of Plain Old Java Objects?

我希望能够创建小型轻量级POJO对象,然后通过原始SQL查询填充它们.我明确地表示希望创建复杂的对象:只是原始对象,没有任何关系.

I want to be able to create small lightweight POJO objects and then have them populated by raw SQL queries. I'm expressly NOT looking to create complex objects: just primitives, with no relationships.

一切似乎都围绕着JPA/JPQL,但这是我不想将对象绑定到特定表的问题.

Everything seems to be centered around JPA/JPQL, but the problem with that is that I do not want to bind my objects to a specific table.

我感觉自己是:

  • (a)服用疯狂药丸,或
  • (b)缺少一些基本知识

推荐答案

轻量级映射器不能作为JDK本身的一部分使用.您可以使用Java的标准 MyBatis (以前称为iBatis).

A lightweight mapper is not available as part of the JDK itself. You could either roll-your-own simple mapper using Java's standard JDBC API (in fact JPA implementations build on top of that) or you could have a look at external libraries that provide simple SQL-to-Object mappers. I know MyBatis (formerly known as iBatis).

A)不,我认为您没有疯狂的想法,B)您是否可能错过了JDBC?

A) No, I think you're not on crazy pills and B) is it possible that you just missed JDBC?

这篇关于将SQL(不是JPQL)映射到简单Java对象的集合吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆