2016-11-02 12 views
0

У меня есть эта странная ошибка, когда я пытаюсь добавить запись в свою базу данных, используя JPA. Ранее я использовал ту же технику для добавления других записей в разные таблицы. Я не понимаю ошибку, которую я получил.По какой-то странной причине я не могу запустить свой JPA-код. «Длина не может быть отрицательной».

Warning: A system exception occurred during an invocation on EJB HelpRequestBean, method: public void sessionBeans.HelpRequestBean.assignHelpRequest(transferClasses.HelpRequestDetails,int) 
    Warning: javax.ejb.EJBException 
     at com.sun.ejb.containers.EJBContainerTransactionManager.processSystemException(EJBContainerTransactionManager.java:750) 
     at com.sun.ejb.containers.EJBContainerTransactionManager.completeNewTx(EJBContainerTransactionManager.java:700) 
     at com.sun.ejb.containers.EJBContainerTransactionManager.postInvokeTx(EJBContainerTransactionManager.java:505) 
     at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4538) 
     at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2019) 
     at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1989) 
     at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:212) 
     at com.sun.ejb.containers.EJBObjectInvocationHandlerDelegate.invoke(EJBObjectInvocationHandlerDelegate.java:79) 
     at com.sun.proxy.$Proxy334.assignHelpRequest(Unknown Source) 
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
     at java.lang.reflect.Method.invoke(Method.java:497) 
     at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie.dispatchToMethod(ReflectiveTie.java:143) 
     at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:173) 
     at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatchToServant(ServerRequestDispatcherImpl.java:528) 
     at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatch(ServerRequestDispatcherImpl.java:199) 
     at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequestRequest(MessageMediatorImpl.java:1549) 
     at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl.java:1425) 
     at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleInput(MessageMediatorImpl.java:930) 
     at com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:213) 
     at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl.java:694) 
     at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.dispatch(MessageMediatorImpl.java:496) 
     at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.doWork(MessageMediatorImpl.java:2222) 
     at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.performWork(ThreadPoolImpl.java:497) 
     at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:540) 
    Caused by: javax.validation.ValidationException: HV000032: Unable to initialize org.hibernate.validator.internal.constraintvalidators.SizeValidatorForCharSequence. 
     at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintValidatorManager.initializeConstraint(ConstraintValidatorManager.java:248) 
     at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintValidatorManager.createAndInitializeValidator(ConstraintValidatorManager.java:147) 
     at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintValidatorManager.getInitializedValidator(ConstraintValidatorManager.java:101) 
     at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateConstraints(ConstraintTree.java:125) 
     at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateConstraints(ConstraintTree.java:91) 
     at org.hibernate.validator.internal.metadata.core.MetaConstraint.validateConstraint(MetaConstraint.java:83) 
     at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraint(ValidatorImpl.java:547) 
     at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForDefaultGroup(ValidatorImpl.java:487) 
     at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForCurrentGroup(ValidatorImpl.java:451) 
     at org.hibernate.validator.internal.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:403) 
     at org.hibernate.validator.internal.engine.ValidatorImpl.validate(ValidatorImpl.java:206) 
     at org.eclipse.persistence.internal.jpa.metadata.listeners.BeanValidationListener.validateOnCallbackEvent(BeanValidationListener.java:104) 
     at org.eclipse.persistence.internal.jpa.metadata.listeners.BeanValidationListener.prePersist(BeanValidationListener.java:78) 
     at org.eclipse.persistence.descriptors.DescriptorEventManager.notifyListener(DescriptorEventManager.java:748) 
     at org.eclipse.persistence.descriptors.DescriptorEventManager.notifyEJB30Listeners(DescriptorEventManager.java:691) 
     at org.eclipse.persistence.descriptors.DescriptorEventManager.executeEvent(DescriptorEventManager.java:229) 
     at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.registerNewObjectClone(UnitOfWorkImpl.java:4314) 
     at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.registerNotRegisteredNewObjectForPersist(UnitOfWorkImpl.java:4291) 
     at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.registerNotRegisteredNewObjectForPersist(RepeatableWriteUnitOfWork.java:521) 
     at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.registerNewObjectForPersist(UnitOfWorkImpl.java:4233) 
     at org.eclipse.persistence.internal.jpa.EntityManagerImpl.persist(EntityManagerImpl.java:507) 
     at com.sun.enterprise.container.common.impl.EntityManagerWrapper.persist(EntityManagerWrapper.java:287) 
     at sessionBeans.HelpRequestBean.assignHelpRequest(HelpRequestBean.java:59) 
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
     at java.lang.reflect.Method.invoke(Method.java:497) 
     at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1081) 
     at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1153) 
     at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:4758) 
     at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:656) 
     at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:836) 
     at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:608) 
     at org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:73) 
     at org.jboss.weld.ejb.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:52) 
     at sun.reflect.GeneratedMethodAccessor232.invoke(Unknown Source) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
     at java.lang.reflect.Method.invoke(Method.java:497) 
     at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:895) 
     at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:835) 
     at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:608) 
     at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doCall(SystemInterceptorProxy.java:163) 
     at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:140) 
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
     at java.lang.reflect.Method.invoke(Method.java:497) 
     at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:895) 
     at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:835) 
     at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:374) 
     at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:4730) 
     at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:4718) 
     at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:205) 
     ... 19 more 
    Caused by: java.lang.IllegalArgumentException: HV000021: The length cannot be negative. 
     at org.hibernate.validator.internal.constraintvalidators.SizeValidatorForCharSequence.validateParameters(SizeValidatorForCharSequence.java:71) 
     at org.hibernate.validator.internal.constraintvalidators.SizeValidatorForCharSequence.initialize(SizeValidatorForCharSequence.java:43) 
     at org.hibernate.validator.internal.constraintvalidators.SizeValidatorForCharSequence.initialize(SizeValidatorForCharSequence.java:33) 
     at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintValidatorManager.initializeConstraint(ConstraintValidatorManager.java:245) 
     ... 71 more 

следующий код:

@Override 
    public void assignHelpRequest(HelpRequestDetails helprequest, int userID) { 
     //Helpreply reply = new Helpreply(Integer.MAX_VALUE, "", "", new Date()); 
     Helpreply reply = new Helpreply(); 
     reply.setRequestID(em.find(Helprequest.class, helprequest.getRequestID())); 
     reply.setUserID(em.find(Users.class, userID)); 
     em.persist(reply); 

     Helprequest request = em.find(Helprequest.class, helprequest.getRequestID()); 
     request.setStatus(1); 
     em.merge(request);  
    } 

Helpreply объект класса.

package database; 

import java.io.Serializable; 
import java.util.Date; 
import javax.persistence.Basic; 
import javax.persistence.Column; 
import javax.persistence.Entity; 
import javax.persistence.GeneratedValue; 
import javax.persistence.GenerationType; 
import javax.persistence.Id; 
import javax.persistence.JoinColumn; 
import javax.persistence.ManyToOne; 
import javax.persistence.NamedQueries; 
import javax.persistence.NamedQuery; 
import javax.persistence.Table; 
import javax.persistence.Temporal; 
import javax.persistence.TemporalType; 
import javax.validation.constraints.NotNull; 
import javax.validation.constraints.Size; 
import javax.xml.bind.annotation.XmlRootElement; 

/** 
* 
* @author Christian 
*/ 
@Entity 
@Table(name = "helpreply") 
@XmlRootElement 
@NamedQueries({ 
    @NamedQuery(name = "Helpreply.findAll", query = "SELECT h FROM Helpreply h"), 
    @NamedQuery(name = "Helpreply.findByReplyID", query = "SELECT h FROM Helpreply h WHERE h.replyID = :replyID"), 
    @NamedQuery(name = "Helpreply.findByTitle", query = "SELECT h FROM Helpreply h WHERE h.title = :title"), 
    @NamedQuery(name = "Helpreply.findByContent", query = "SELECT h FROM Helpreply h WHERE h.content = :content"), 
    @NamedQuery(name = "Helpreply.findByCreationDate", query = "SELECT h FROM Helpreply h WHERE h.creationDate = :creationDate")}) 
public class Helpreply implements Serializable { 

    private static final long serialVersionUID = 1L; 
    @Id 
    @GeneratedValue(strategy = GenerationType.IDENTITY) 
    @Basic(optional = false) 
    @Column(name = "replyID") 
    private Integer replyID; 
    @Basic(optional = false) 
    @NotNull 
    @Size(min = 1, max = 0) 
    @Column(name = "title") 
    private String title; 
    @Basic(optional = false) 
    @NotNull 
    @Size(min = 1, max = 0) 
    @Column(name = "content") 
    private String content; 
    @Basic(optional = false) 
    @NotNull 
    @Column(name = "creationDate") 
    @Temporal(TemporalType.DATE) 
    private Date creationDate; 
    @JoinColumn(name = "userID", referencedColumnName = "userID") 
    @ManyToOne(optional = false) 
    private Users userID; 
    @JoinColumn(name = "requestID", referencedColumnName = "requestID") 
    @ManyToOne(optional = false) 
    private Helprequest requestID; 

    public Helpreply() { 
    } 

    public Helpreply(Integer replyID) { 
     this.replyID = replyID; 
    } 

    public Helpreply(Integer replyID, String title, String content, Date creationDate) { 
     this.replyID = replyID; 
     this.title = title; 
     this.content = content; 
     this.creationDate = creationDate; 
    } 

    public Integer getReplyID() { 
     return replyID; 
    } 

    public void setReplyID(Integer replyID) { 
     this.replyID = replyID; 
    } 

    public String getTitle() { 
     return title; 
    } 

    public void setTitle(String title) { 
     this.title = title; 
    } 

    public String getContent() { 
     return content; 
    } 

    public void setContent(String content) { 
     this.content = content; 
    } 

    public Date getCreationDate() { 
     return creationDate; 
    } 

    public void setCreationDate(Date creationDate) { 
     this.creationDate = creationDate; 
    } 

    public Users getUserID() { 
     return userID; 
    } 

    public void setUserID(Users userID) { 
     this.userID = userID; 
    } 

    public Helprequest getRequestID() { 
     return requestID; 
    } 

    public void setRequestID(Helprequest requestID) { 
     this.requestID = requestID; 
    } 

    @Override 
    public int hashCode() { 
     int hash = 0; 
     hash += (replyID != null ? replyID.hashCode() : 0); 
     return hash; 
    } 

    @Override 
    public boolean equals(Object object) { 
     // TODO: Warning - this method won't work in the case the id fields are not set 
     if (!(object instanceof Helpreply)) { 
      return false; 
     } 
     Helpreply other = (Helpreply) object; 
     if ((this.replyID == null && other.replyID != null) || (this.replyID != null && !this.replyID.equals(other.replyID))) { 
      return false; 
     } 
     return true; 
    } 

    @Override 
    public String toString() { 
     return "database.Helpreply[ replyID=" + replyID + " ]"; 
    } 

} 
+1

Кажется, в классе 'Helpreply' есть аннотация« Проверка компонента », которая неверно указывает, что длина строкового значения должна быть меньше нуля. Отправьте код для 'Helpreply' на ваш вопрос. – OndrejM

+0

Привет, спасибо за ваш комментарий. Я добавил класс сущности :-) –

ответ

1

Спасибо за комментарии, которые я получил.

Что мне нужно, чтобы избавиться от ошибок было удалить

@Size(min = 1, max = 0) 

Из моего класса сущностей. Именно по этой причине я получил ошибку. Я думаю, что это объясняет сам, почему это не сработало :-)

 Смежные вопросы

  • Нет связанных вопросов^_^