I have a question. Of course, I have previously looked on the Internet and searched for the solution. Unfortunately, I have not found a solution.
I have a Spring Boot application that processes the information from customers. But this application should not point to a table as usual but to a view that requests information from two tables. How do I have to modify my entity to refenence to the view?
My View
CREATE VIEW customers_view
SELECT
customer_id, firstname, lastname,
(SELECT ordernumber FROM orders
WHERE orders.customer_id = custoumer.id
ORDER BY customer_id DESC)
FROM customers
My Entity
@Entity
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class CustomerInformation {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@EqualsAndHashCode.Exclude
private Long id;
@Column(name = "customer_id")
private Long customer_id;
@Column(name = "firstname")
private String firstname;
@Column(name = "lastname")
private String firstname;
@Column(name = "ordernumber")
private String firstname;
}
Here are some examples for referencing views using spring boot:
JPA/SpringBoot Repository for database view (not table)