将SQL视图映射到hibernate jpa实体 [英] Mapping an SQL View to a hibernate jpa Entity
问题描述
我在Postgresql中创建了一个视图
CREATE OR REPLACE VIEW tenant3.user_accounts AS
SELECT foo。 c1
FROM tenant3.dblink('dbname = genesis_admin':: text,'SELECT username FROM user_account':: text)foo(c1 text);
我想创建映射到此视图的JPA实体,以便我可以查询使用的视图Spring Data JPA。可能吗?如果是这样,怎么样?
我如何将所述视图映射到Spring Data JPA实体?
是的,可以将视图映射到JPA实体。毕竟,JPA不区分表和视图。只要确保该视图具有主键(一列或一组非空的列并标识该行)。
如果您不希望实体只读,请添加适当的规则和/或触发器。
I've created a view in Postgresql
CREATE OR REPLACE VIEW tenant3.user_accounts AS
SELECT foo.c1
FROM tenant3.dblink('dbname=genesis_admin'::text, 'SELECT username FROM user_account'::text) foo(c1 text);
I want to create a JPA entity that maps to this View so that I can query the said view using Spring Data JPA. is it possible? if so, how?
How would I map the said view to a Spring Data JPA Entity?
Yes, it is possible to map views to JPA entities. After all, JPA does not distinguish between tables and views. Just make sure that the view has a "primary key" (a column or a group of columns that are not null and identify the row).
If you don't want the entity to be read only, add the appropriate rules and/or triggers.
这篇关于将SQL视图映射到hibernate jpa实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!