我正在尝试使用 jpa 验证来验证新的 bean 对象。
我收到此错误:
2012-09-24 11:19:55,584 WARN [AbstractModel:32] The object is not persisted yet, this operation requires the object to already be persisted.
java.lang.Exception
at org.oscarehr.common.model.AbstractModel.hashCode(AbstractModel.java:32)
at org.hibernate.validator.engine.ConstraintViolationImpl.hashCode(ConstraintViolationImpl.java:127)
at java.util.HashMap.put(HashMap.java:389)
at java.util.HashSet.add(HashSet.java:217)
at java.util.AbstractCollection.addAll(AbstractCollection.java:322)
at java.util.HashSet.<init>(HashSet.java:117)
at org.hibernate.validator.engine.ValidatorImpl.validate(ValidatorImpl.java:120)
at org.apache.jsp.billing.CA.ON.reports.billingONNewReport_jsp.saveSubmittedBills(billingONNewReport_jsp.java:383)
at org.apache.jsp.billing.CA.ON.reports.billingONNewReport_jsp._jspService(billingONNewReport_jsp.java:796)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
at org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:709)
at org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:680)
at org.apache.jsp.billing.CA.ON.billingONReport_jsp._jspService(billingONReport_jsp.java:109)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
....
我正在使用:
hibernate-entitymanager 3.4.0.GA
hibernate-validator 4.1.0.Final
validation-api 1.0.0.GA
我这样调用我的验证代码:
Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
Set<ConstraintViolation<BillingClaimHeader1>> constraintViolations = validator.validate(newBill);
MiscUtils.getLogger().info("num violations: " + constraintViolations.size());
newBill
class 的新实例在哪里BillingClaimHeader1
。
这是 的类定义BillingClaimHeader1
:
public class BillingClaimHeader1 extends AbstractModel<Integer> implements Serializable
我对整个 JPA/验证这件事还是很陌生,但我没有意识到在验证它之前我必须坚持一个对象......似乎有点违反直觉......
我很感激任何帮助!
干杯
贾勒特