Does JPA support mapping to sql views?

前端 未结 3 715
野趣味
野趣味 2020-12-04 17:56

I\'m currently using Eclipselink, but I know now days most JPA implementations have been pretty standardized. Is there a native way to map a JPA entity to a view? I am not l

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-04 18:33

    While using the @Id annotation with fields of directly supported types is not the only way to specify an entity's identity (see @IdClass with multiple @Id annotations or @EmbeddedId with @Embedded), the JPA specification requires a primary key for each entity.

    That said, you don't need entities to use JPA with database views. As mapping to a view is no different from mapping to a table from an SQL perspective, you could still use native queries (createNativeQuery on EntityManager) to retrieve scalar values instead.

提交回复
热议问题