我有订单和订单欺诈警报。该关联仅从欺诈警报运行到订单,反之亦然。
public class FraudAlerts
...
@ManyToOne
@JoinColumn(name = "customerOrderId")
private CustomerOrder customerOrder;
我的查询是这样的:
"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");
您可以看到我使用子查询来获取与此订单相关的所有欺诈警报名称作为集合并将其传递给视图模型 bean FraudOrderSearchViewModel。
我的问题是hibernate找不到合适的构造函数并抛出异常:
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)
我的构造函数如下:
public FraudOrderSearchViewModel(final String orderId, final Date datePlaced, final BigDecimal originalTotal, final String customerEmail, final String customerId,
final String ipAddress, final Object[] holdReason)
我试过 String[], List List 无济于事。hibernate 希望我使用的构造函数变量的类型是什么?