By using a constructor in the SELECT
clause we can instantiate a Java object with the results of our query. This Java object does not need to be an entity or be mapped onto a database. The class name corresponding to this object must be fully qualified. For example, the query
SELECT NEW ejb30.entity.CustomerRef( c.firstName, c.lastName, c.referee.name) FROM Customer c
creates a CustomerRef
object which contains a customer's first and last name together with the associated referee name. The following is a partial listing for the CustomerRef
class:
package ejb30.entity; import java.io.Serializable; public class CustomerRef implements Serializable { private String firstName; private String lastName; private String refereeName; public CustomerRef() {} public CustomerRef(String firstName, String lastName, String refereeName) { this.firstName = firstName; this.lastName = lastName; this.refereeName = refereeName; } // getter and setter methods }
Note the presence of a...