Reputation: 109
I am using Spring Data to load an object and all works well...However, I don't want to load the entire object as I am returning a list to display in a table, so I only want to load what is in the table. then, when a user selects "details" I want to make an AJAX call to the server to load the entire object. My thought was to have a Base Class "TableView" then to have a subclass "Class DetailsView extends TableView". I could probably create a new repository, so one for the TableView and one for the DetailsView, but I'm wondering if there is a way to use the same repository class? below is an example of what I'd like to do, but I'm not sure how to change the repositoryClass to achieve what I want...I get the following error:
SQLGrammarException: could not extract ResultSet at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:261)
class TableView{
String title;
}
class DetailsView extends TableView{
String details;
}
interface ITableViewRepository extends CrudRepository<TableView, Integer>{
Upvotes: 1
Views: 198
Reputation: 6748
You can write two queries in your TableViewRepository
.
One for returning id
and title
from you object
@Query("SELECT tv.id, tv.title FROM TableView tv")
TableView findWithTitles();
And after that just call a method findOne
with TableView
id
to return entire object.
Upvotes: 1