Hibernate JPA @NamedQueries Example

@NamedQueries

The @NamedQueries annotation is used to group multiple @NamedQuery annotations. NamedQueries specifies multiple named Java Persistence query language queries. Query names are scoped to the persistence unit. The NamedQueries annotation can be applied to an entity or mapped superclass.

Example:


@NamedQueries({
    @NamedQuery(
        name = "get_phone_by_number",
        query = "select p " +
                "from Phone p " +
                "where p.number = :number",
        timeout = 1,
        readOnly = true
    )
})

Phone phone = entityManager
.createNamedQuery( "get_phone_by_number", Phone.class )
.setParameter( "number", "123-456-7890" )
.getSingleResult();


Comments

Popular posts from this blog

Spring Elasticsearch Operations

Object oriented programming concepts (OOPs)

Spring Boot and Vaadin : Filtering rows in Vaadin Grid