Skip to content
Advertisement

how do i fetch derived/calculated column from database view or Procedure in Spring Boot using JPA/Hibernate and use it along with predefined columns?

I am working on a project as am learning Spring Boot with JPA,Hibernate with Mustache as for templates. i managed to create a view with one calculated column which calculates an remaining days from issueDate and expiryDate. the view works fine and i am able to display all columns except the calculated column. I need help figuring out how to do that

My Entity Class

JavaScript

my Repo

JavaScript

My Database VIEW

JavaScript

My Controller:

JavaScript

I want to be able to list that days_remaining column along with the rest of the columns on my mustache view.

StackTrace :

JavaScript

@Jens Schauder per your previous comments will this do? I can share the project files if that would help.

Advertisement

Answer

You should EITHER use @Formula or a database view.

Since you made it clear that you prefer the view you should:

  1. Map your entity to your view:

    JavaScript
  2. Make sure JPA does not try to write the column, but only read it.

    JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement