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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…