0

I'm trying to implement a Repository to work with Views. The fact is that I'm trying to use the SimpleJpaRepository implementation, but I'm getting a lot of errors on execution time because my DTO is not an @Entity. It is only a @Table, and it seems that this kind of elements are not mapped into the Metamodel of JPA.

This is my DTO:

@Table(name = "v_language")
public class VLanguage {

    @Column(name = "isocode")
    private String isocode;

    @Column(name = "name")
    private String name;

    @Column(name = "isdefault")
    private String isdefault;

    // getters and setters
    ...
}

I tried to define a customized base repository with minimal functionality (only a findAll() method) with the same implementation of SimpleJpaRepository, but when building the Query it fails when doing:

Root<U> root = query.from(domainClass);

With this exception:

Caused by: java.lang.IllegalArgumentException: Not an entity: class es.prodevelop.pui.common.jpa.model.views.dto.VLanguage
    at org.hibernate.jpa.internal.metamodel.MetamodelImpl.entity(MetamodelImpl.java:194)
    at org.hibernate.jpa.criteria.QueryStructure.from(QueryStructure.java:124)
    at org.hibernate.jpa.criteria.CriteriaQueryImpl.from(CriteriaQueryImpl.java:156)
    at es.prodevelop.pui.common.jpa.configuration.AbstractRepository.applySpecificationToCriteria(AbstractRepository.java:213)
    at es.prodevelop.pui.common.jpa.configuration.AbstractRepository.getQuery(AbstractRepository.java:174)
    at es.prodevelop.pui.common.jpa.configuration.AbstractRepository.findAll(AbstractRepository.java:151)
    ...

Does anybody know how to solve it?

Marc Gil Sendra
  • 819
  • 2
  • 9
  • 22

1 Answers1

0

you are missing the @Entity annotation. please annotate your class and try again.

Apostolos
  • 10,033
  • 5
  • 24
  • 39
  • Yes I know, but if I set the `@Entity` annotation, I'm forced to set an @Id, and views has no @Id columns. I read about setting a fakeId, but it doesn't work when creating the queries, because JPA includes this column to the query... – Marc Gil Sendra Jul 14 '16 at 12:50
  • what is the problem with the queries? didnt get it – Apostolos Jul 14 '16 at 12:55
  • you can annotate with @Id all the columns that create the unique key for this view. – Apostolos Jul 14 '16 at 12:58
  • This is the only solution I found, thanks (http://stackoverflow.com/a/7593869/1771308). Nevertheless, I will try to find a more elegant solution... ;) – Marc Gil Sendra Jul 14 '16 at 13:05
  • that's what i said in my previous comment actually :) – Apostolos Jul 14 '16 at 13:13