Reputation: 43
I am getting result if I use SQL in @Subselect. Is it possible use HQL in this annotation?
@Entity
@Subselect("select * from Foo_table")
public class FooView
Like
@Entity
@Subselect("select a from FooEntity a")
public class FooView
Upvotes: 2
Views: 1820
Reputation: 875
I suppose it is not possible, because according to https://docs.jboss.org/hibernate/orm/3.6/reference/en-US/html/mapping.html#mapping-declaration-class
There is no difference between a view and a base table for a Hibernate mapping. This is transparent at the database level, although some DBMS do not support views properly, especially with updates. Sometimes you want to use a view, but you cannot create one in the database (i.e. with a legacy schema). In this case, you can map an immutable and read-only entity to a given SQL subselect expression using @org.hibernate.annotations.Subselect
and it will be directly executed as query statement for DB, without HQL layer and transformation from HQL to pure SQL... but you can play with it and test
Upvotes: 1