title: Hibernate/JPA query language new entity constructor with subquery - unable to locate appropriate constructor
body: <p>I have an order and an order fraud alert. The association runs only from the fraud alert to the order, not vice versa. </p>
  
  <pre><code>public class FraudAlerts
  ...
  @ManyToOne
  @JoinColumn(name = "customerOrderId")
  private CustomerOrder customerOrder;
  </code></pre>
  
  <p>My query is this:</p>
  
  <pre><code>"select new com.acme.struts.search.FraudOrderSearchViewModel"
  + "(co.orderId, co.orderPlacedDate, tot.totalIncVat, adr.email, co.customerNumber, co.ipAddress, "
  + "(select name from FraudAlerts where co.orderId = customerOrder))"
  + " from CustomerOrder as co join co.customerBillTo adr join co.originalTotal as tot");
  </code></pre>
  
  <p>You can see I use subquery to get all fraudAlert names that that are accociated with this order as a collection and pass that to the view model bean FraudOrderSearchViewModel.</p>
  
  <p>My problem is that hibernate won't find the appropriate constructor for it and throws an exception:</p>
  
  <pre><code>java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: Unable to locate appropriate constructor on class [com.acme.struts.search.FraudOrderSearchViewModel] [select new com.acme.struts.search.FraudOrderSearchViewModel(co.orderId, co.orderPlacedDate, tot.totalIncVat, adr.email, co.customerNumber, co.ipAddress, (select name from com.acme.data.model.fraud.FraudAlerts where co.orderId = customerOrder)) from com.acme.data.model.customer.CustomerOrder as co join co.customerBillTo adr join co.originalTotal as tot]
  at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1364)
  at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1300)
  at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:294)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  at java.lang.reflect.Method.invoke(Method.java:597)
  at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:240)
  at $Proxy65.createQuery(Unknown Source)
  at com.acme.services.fraud.FraudHibQueryTest.testFraudServiceHibQuery(FraudHibQueryTest.java:72)
  </code></pre>
  
  <p>My constructor is the following:</p>
  
  <pre><code>    public FraudOrderSearchViewModel(final String orderId, final Date datePlaced, final BigDecimal originalTotal, final String customerEmail, final String customerId,
          final String ipAddress, final Object[] holdReason)
  </code></pre>
  
  <p>I tried String[], List List to no avail. What is the type of constructor variable that hibernate wants me to use?</p>