我有订单和订单欺诈提醒。该关联仅从欺诈警报运行到订单,反之亦然。
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");
您可以看到我使用子查询将与此订单相关联的所有fraudAlert名称作为集合并将其传递给视图模型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要我使用的构造函数变量的类型是什么?
答案 0 :(得分:1)
我发现我只是在关系模型中遇到了限制。我试图获取一个DB行列表,其中每个行都包含一个列,该列由另一个表中的多行组成。只能进行一次查询。
答案 1 :(得分:-1)
你的hibernate实体FraudOrderSearchViewModel
应该有一个默认的无参数构造函数。
答案 2 :(得分:-1)
此问题的一个原因是您从查询中的表中检索列的顺序。它必须与构造函数中的相同。