简体   繁体   English

使用 Spring boot JPA 从现有的 oracle db 获取数据

[英]Using Spring boot JPA getting data from existing oracle db

Hi I have an existing oracle db, which contains tables.嗨,我有一个现有的 oracle 数据库,其中包含表。 Need to get data from multiple tables using jpa from spring boot api below are my questions需要从下面的spring boot api使用jpa从多个表中获取数据是我的问题

  1. Do I need model classes of those multiple tables or I don't need model classes to get the required column data?我需要那些多个表的模型类还是不需要模型类来获取所需的列数据? 2.Can I write a custom query joining multiple tables and get the list of values from my db using jpa? 2.我可以编写一个连接多个表的自定义查询并使用 jpa 从我的数据库中获取值列表吗?

I presume you are trying to expose the query results as a spring boot rest API.我假设您正在尝试将查询结果公开为 Spring Boot Rest API。 You need to have some object definition to hold the query results into memory.您需要有一些对象定义来将查询结果保存到内存中。 It is always a good idea to have a model to represent your query results for better manageability and maintainability of code.使用模型来表示查询结果以提高代码的可管理性和可维护性始终是一个好主意。 Certainly, you can achieve it without creating any models by storing all the results into a Map.当然,您可以通过将所有结果存储到 Map 来实现它,而无需创建任何模型。

If you don't use models then you will be missing key features of ORM tools.如果您不使用模型,那么您将缺少 ORM 工具的关键功能。

Just to answer your questions -只为回答你的问题——

  1. Do I need model classes of those multiple tables or I don't need model classes to get the required column data?我需要那些多个表的模型类还是不需要模型类来获取所需的列数据?

    Answer: Not required but recommended to use model classes.答:不是必需的,但建议使用模型类。

  2. Can I write a custom query joining multiple tables and get the list of values from my db using jpa?我可以编写一个加入多个表的自定义查询并使用 jpa 从我的数据库中获取值列表吗?

    Answer: You can write the native SQL query by joining multiple tables.答:可以通过加入多个表来编写本机 SQL 查询。

You can find more examples here您可以在此处找到更多示例

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Spring Boot上从不使用JPA的Oracle获取数据 - How to get data from oracle without jpa on spring boot 无法使用 Spring 引导和 JPA 在 MySQL 8 DB 中插入数据 - Not able to insert data in MySQL 8 DB using Spring Boot and JPA 制作Spring Boot应用程序以从现有的oracle数据库加载数据吗? - Making a spring boot app to load data from an existing oracle database? 从 mysql 数据库获取 JSONArray 使用 Spring 启动 JPA - Getting JSONArray from mysql database Using Spring boot JPA 使用spring data jpa从db过滤和检索数据 - Filtering and retrieving data from db using spring data jpa 在 spring JPA 中使用 @Query 从 db 获取数据时出现 java.lang.NullPointerException。 虽然查询返回 MySql 中的数据 - java.lang.NullPointerException while getting data from db using @Query in spring JPA. Though query returns data in MySql 如何使用 Spring Boot 的 JPA 存储库中的映射从 spring 引导中的多个表中获取数据 - How to fetch data from multiple tables in spring boot using mapping in Spring Boot's JPA repository Spring Boot Data Rest JPA:@ManyToOne未填充数据库中的ForeignKey列 - Spring Boot Data Rest JPA: @ManyToOne not populating the ForeignKey column in DB Spring Boot Data JPA与DB / 2 Configuration和JUnit有关 - Spring Boot Data JPA issues with DB/2 Configuration and JUnit Spring Boot JPA 不使用 findById 返回现有结果 - Spring boot JPA no returning existing result using findById
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM