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
package com.demgo.demgoerp.model;
import org.hibernate.annotations.Formula;
import org.hibernate.annotations.GenericGenerator;
import javax.persistence.*;
@Entity
public class DocumentStorage
{
@Id
@GeneratedValue(strategy = GenerationType.AUTO, generator = "native")
@GenericGenerator(name = "native", strategy = "native")
// @Column(name = "id", updatable = false, nullable = false)
private Long documentID;
private String documentTitle;
private String documentLocation;
private String uploadDate;
private String issueDate;
private String expiryDate;
/* @Formula(value = "select CONCAT(documentLocation,documentTitle) from document_storage")
private String myColumn;*/
public DocumentStorage()
{
super();
}
public DocumentStorage(String documentTitle, String documentLocation, String uploadDate, String issueDate, String expiryDate)
{
super();
this.documentTitle = documentTitle;
this.documentLocation = documentLocation;
this.uploadDate = uploadDate;
this.issueDate = issueDate;
this.expiryDate = expiryDate;
}
public Long getDocumentID()
{
return documentID;
}
public void setDocumentID(Long documentID)
{
this.documentID = documentID;
}
public String getDocumentTitle()
{
return documentTitle;
}
public void setDocumentTitle(String documentTitle)
{
this.documentTitle = documentTitle;
}
public String getDocumentLocation()
{
return documentLocation;
}
public void setDocumentLocation(String documentLocation)
{
this.documentLocation = documentLocation;
}
public String getUploadDate()
{
return uploadDate;
}
public void setUploadDate(String uploadDate)
{
this.uploadDate = uploadDate;
}
public String getIssueDate()
{
return issueDate;
}
public void setIssueDate(String issueDate)
{
this.issueDate = issueDate;
}
public String getExpiryDate()
{
return expiryDate;
}
public void setExpiryDate(String expiryDate)
{
this.expiryDate = expiryDate;
}
}
my Repo
package com.demgo.demgoerp.dao;
import com.demgo.demgoerp.model.DocumentStorage;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface DocumentRepo extends JpaRepository<DocumentStorage, Long>
{
@Query(value = "select * from ShowAllDocuments", nativeQuery = true)
List<DocumentStorage> findAllDocuments();
@Query(nativeQuery = true, value = "select * from document_storage")
public List<DocumentStorage> getAllDocs();
}
My Database VIEW
create view ShowAllDocuments
as
SELECT
documentid,
document_location,
document_title,
upload_date,
issue_date,
expiry_date,
datediff(expiry_date,issue_date) as days_remaining
FROM document_storage;
Now i just want to be able to list that days_remaining column with the rest of the columns on my mustache view.