javax.persistence

Annotation Type ConstructorResult


  • @Target(value={})
     @Retention(value=RUNTIME)
    public @interface ConstructorResult
    Used in conjunction with the SqlResultSetMapping annotation to map the SELECT clause of a SQL query to a constructor.

    Applies a constructor for the target class, passing in as arguments values from the specified columns. All columns corresponding to arguments of the intended constructor must be specified using the columns element of the ConstructorResult annotation in the same order as that of the argument list of the constructor. Any entities returned as constructor results will be in either the new or detached state, depending on whether a primary key is retrieved for the constructed object.

    
     Example:
    
       Query q = em.createNativeQuery(
          "SELECT c.id, c.name, COUNT(o) as orderCount, AVG(o.price) AS avgOrder " +
          "FROM Customer c, Orders o " +
          "WHERE o.cid = c.id " +
          "GROUP BY c.id, c.name",
          "CustomerDetailsResult");
    
       @SqlResultSetMapping(
           name="CustomerDetailsResult",
           classes={
              @ConstructorResult(
                   targetClass=com.acme.CustomerDetails.class,
                     columns={
                        @ColumnResult(name="id"),
                        @ColumnResult(name="name"),
                        @ColumnResult(name="orderCount"),
                        @ColumnResult(name="avgOrder", type=Double.class)
                        }
              )
           }
          )
    
     
    Since:
    Java Persistence 2.1
    See Also:
    SqlResultSetMapping, ColumnResult
    • Element Detail

      • targetClass

        public abstract Class targetClass
        (Required) The class whose constructor is to be invoked.
      • columns

        public abstract ColumnResult[] columns
        (Required) The mapping of columns in the SELECT list to the arguments of the intended constructor, in order.

Document created the 11/06/2005, last modified the 18/08/2025
Source of the printed document:https://www.gaudry.be/en/java-api-javaee-rf-javax/persistence/ConstructorResult.html

The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.

References

  1. View the html document Language of the document:fr Manuel PHP : https://docs.oracle.com, ConstructorResult (Java(TM) EE 7 Specification APIs)

These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author of this site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.