持久化实体时出现 javax.ejb.EJBException

发布于 2024-11-15 23:56:26 字数 11806 浏览 1 评论 0原文

我有一个名为 Medico 的实体,它是从数据库创建为实体类的,因此我认为实体定义在这里是安全的,尽管如此,定义如下:

@Entity
@Table(name = "medico")
@XmlRootElement
@NamedQueries({All named queries here})
public class Medico implements Serializable {
private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @NotNull
    @Column(name = "idMedico")
    private Integer idMedico;
    @Basic(optional = false)
    @NotNull
    @Column(name = "Identificacion")
    private int identificacion;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 33)
    @Column(name = "Primer_Nombre")
    private String primerNombre;
    @Size(max = 33)
    @Column(name = "Segundo_Nombre")
    private String segundoNombre;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 33)
    @Column(name = "Primer_Apellido")
    private String primerApellido;
    @Size(max = 33)
    @Column(name = "Segundo_Apellido")
    private String segundoApellido;
    @Basic(optional = false)
    @NotNull
    @Column(name = "Telefono")
    private long telefono;
    @Column(name = "Telefono_Celular")
    private BigInteger telefonoCelular;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 33)
    @Column(name = "Direccion")
    private String direccion;
    // Constructors..
    // Getters and setters..
}

我想创建新的 Medico< /em> MySql 数据库上的实体,这就是我这样做的方式:

@ManagedBean
@ViewScoped
public class ConsultaMedicos implements Serializable {
// Variables Definition ..
@EJB
private DoctorsFacadeLocal doctorsFacade; 
// Constructor and other methods ..
public String save()
    {
        try{
            doctorsFacade.save(consultedDoctor);
            FacesMessage fm = new FacesMessage(FacesMessage.SEVERITY_INFO, CREATE_SUMMARY, null);
            FacesContext.getCurrentInstance().addMessage(CREATE_SUMMARY, fm);
        }
        catch(Exception ex){
            FacesMessage fm = new FacesMessage(FacesMessage.SEVERITY_ERROR, CREATE_ERROR_SUMMARY, null);
            FacesContext.getCurrentInstance().addMessage(CREATE_ERROR_SUMMARY, fm);
            return null;
        }
        return "listaMedicos.xhtml";
    }
...
}  

@Local
public interface DoctorsFacadeLocal {

    List<Medico> findAllDoctors();
    Medico findDoctorByIdNumber(int identificacion);
    void edit(Medico medico);
    void save(Medico medico);
}  

@Stateless
public class DoctorsFacade implements DoctorsFacadeLocal {

    @PersistenceContext
    private EntityManager em;
// Other methods.. 
    @Override
    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    public void save(Medico medico)
    {
        em.persist(medico);
        em.flush();
    }
}

从 JSF 页面调用 save() 后,出现以下异常:

javax.ejb.EJBException
    at com.sun.ejb.containers.BaseContainer.processSystemException(BaseContainer.java:5194)
    at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:5092)
    at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4880)
    at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2039)
    at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1990)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:222)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:88)
    at $Proxy157.save(Unknown Source)
    at com.lemm.web.bean.ConsultaMedicos.save(ConsultaMedicos.java:89)
    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 javax.el.BeanELResolver.invokeMethod(BeanELResolver.java:737)
    at javax.el.BeanELResolver.invoke(BeanELResolver.java:467)
    at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:254)
    at com.sun.el.parser.AstValue.invoke(AstValue.java:228)
    at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:297)
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
    at javax.faces.component.UICommand.broadcast(UICommand.java:315)
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:409)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1534)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)
    at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:326)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:227)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:170)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:822)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:719)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1013)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
    at java.lang.Thread.run(Thread.java:662)
Caused by: javax.validation.ConstraintViolationException: Bean Validation constraint(s) violated while executing Automatic Bean Validation on callback event:'prePersist'. Please refer to embedded ConstraintViolations for details.
    at org.eclipse.persistence.internal.jpa.metadata.listeners.BeanValidationListener.validateOnCallbackEvent(BeanValidationListener.java:90)
    at org.eclipse.persistence.internal.jpa.metadata.listeners.BeanValidationListener.prePersist(BeanValidationListener.java:62)
    at org.eclipse.persistence.descriptors.DescriptorEventManager.notifyListener(DescriptorEventManager.java:698)
    at org.eclipse.persistence.descriptors.DescriptorEventManager.notifyEJB30Listeners(DescriptorEventManager.java:641)
    at org.eclipse.persistence.descriptors.DescriptorEventManager.executeEvent(DescriptorEventManager.java:200)
    at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.registerNewObjectClone(UnitOfWorkImpl.java:4216)
    at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.cloneAndRegisterNewObject(RepeatableWriteUnitOfWork.java:576)
    at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalRegisterObject(UnitOfWorkImpl.java:2883)
    at org.eclipse.persistence.internal.sessions.MergeManager.registerObjectForMergeCloneIntoWorkingCopy(MergeManager.java:932)
    at org.eclipse.persistence.internal.sessions.MergeManager.mergeChangesOfCloneIntoWorkingCopy(MergeManager.java:492)
    at org.eclipse.persistence.internal.sessions.MergeManager.mergeChanges(MergeManager.java:263)
    at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.mergeCloneWithReferences(UnitOfWorkImpl.java:3467)
    at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.mergeCloneWithReferences(RepeatableWriteUnitOfWork.java:363)
    at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.mergeCloneWithReferences(UnitOfWorkImpl.java:3427)
    at org.eclipse.persistence.internal.jpa.EntityManagerImpl.mergeInternal(EntityManagerImpl.java:452)
    at org.eclipse.persistence.internal.jpa.EntityManagerImpl.merge(EntityManagerImpl.java:429)
    at com.sun.enterprise.container.common.impl.EntityManagerWrapper.merge(EntityManagerWrapper.java:286)
    at com.lemm.ejb.facade.DoctorsFacade.save(DoctorsFacade.java:61)
    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.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1052)
    at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1124)
    at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:5367)
    at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:619)
    at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:801)
    at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:571)
    at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doAround(SystemInterceptorProxy.java:162)
    at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:144)
    at sun.reflect.GeneratedMethodAccessor78.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:862)
    at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:801)
    at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:371)
    at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:5339)
    at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:5327)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:214)
    ... 47 more

我做错了什么?我错过了什么?
如果它有任何作用,那就是我的 persistence.xml

<persistence-unit name="lemmPU" transaction-type="JTA">
    <jta-data-source>jdbc/lemmdb</jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
    </properties>
</persistence-unit>

I have an entity called Medico which was created as an Entity Class from Database, hence I think the entity definition is failsafe here, nevertheless the definition is the following:

@Entity
@Table(name = "medico")
@XmlRootElement
@NamedQueries({All named queries here})
public class Medico implements Serializable {
private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @NotNull
    @Column(name = "idMedico")
    private Integer idMedico;
    @Basic(optional = false)
    @NotNull
    @Column(name = "Identificacion")
    private int identificacion;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 33)
    @Column(name = "Primer_Nombre")
    private String primerNombre;
    @Size(max = 33)
    @Column(name = "Segundo_Nombre")
    private String segundoNombre;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 33)
    @Column(name = "Primer_Apellido")
    private String primerApellido;
    @Size(max = 33)
    @Column(name = "Segundo_Apellido")
    private String segundoApellido;
    @Basic(optional = false)
    @NotNull
    @Column(name = "Telefono")
    private long telefono;
    @Column(name = "Telefono_Celular")
    private BigInteger telefonoCelular;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 33)
    @Column(name = "Direccion")
    private String direccion;
    // Constructors..
    // Getters and setters..
}

I want to create new Medico entities on MySql database, and this is how I am doing so:

@ManagedBean
@ViewScoped
public class ConsultaMedicos implements Serializable {
// Variables Definition ..
@EJB
private DoctorsFacadeLocal doctorsFacade; 
// Constructor and other methods ..
public String save()
    {
        try{
            doctorsFacade.save(consultedDoctor);
            FacesMessage fm = new FacesMessage(FacesMessage.SEVERITY_INFO, CREATE_SUMMARY, null);
            FacesContext.getCurrentInstance().addMessage(CREATE_SUMMARY, fm);
        }
        catch(Exception ex){
            FacesMessage fm = new FacesMessage(FacesMessage.SEVERITY_ERROR, CREATE_ERROR_SUMMARY, null);
            FacesContext.getCurrentInstance().addMessage(CREATE_ERROR_SUMMARY, fm);
            return null;
        }
        return "listaMedicos.xhtml";
    }
...
}  

@Local
public interface DoctorsFacadeLocal {

    List<Medico> findAllDoctors();
    Medico findDoctorByIdNumber(int identificacion);
    void edit(Medico medico);
    void save(Medico medico);
}  

@Stateless
public class DoctorsFacade implements DoctorsFacadeLocal {

    @PersistenceContext
    private EntityManager em;
// Other methods.. 
    @Override
    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    public void save(Medico medico)
    {
        em.persist(medico);
        em.flush();
    }
}

After I call save() from my JSF page, I get the following exception:

javax.ejb.EJBException
    at com.sun.ejb.containers.BaseContainer.processSystemException(BaseContainer.java:5194)
    at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:5092)
    at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4880)
    at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2039)
    at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1990)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:222)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:88)
    at $Proxy157.save(Unknown Source)
    at com.lemm.web.bean.ConsultaMedicos.save(ConsultaMedicos.java:89)
    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 javax.el.BeanELResolver.invokeMethod(BeanELResolver.java:737)
    at javax.el.BeanELResolver.invoke(BeanELResolver.java:467)
    at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:254)
    at com.sun.el.parser.AstValue.invoke(AstValue.java:228)
    at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:297)
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
    at javax.faces.component.UICommand.broadcast(UICommand.java:315)
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:409)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1534)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)
    at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:326)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:227)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:170)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:822)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:719)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1013)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
    at java.lang.Thread.run(Thread.java:662)
Caused by: javax.validation.ConstraintViolationException: Bean Validation constraint(s) violated while executing Automatic Bean Validation on callback event:'prePersist'. Please refer to embedded ConstraintViolations for details.
    at org.eclipse.persistence.internal.jpa.metadata.listeners.BeanValidationListener.validateOnCallbackEvent(BeanValidationListener.java:90)
    at org.eclipse.persistence.internal.jpa.metadata.listeners.BeanValidationListener.prePersist(BeanValidationListener.java:62)
    at org.eclipse.persistence.descriptors.DescriptorEventManager.notifyListener(DescriptorEventManager.java:698)
    at org.eclipse.persistence.descriptors.DescriptorEventManager.notifyEJB30Listeners(DescriptorEventManager.java:641)
    at org.eclipse.persistence.descriptors.DescriptorEventManager.executeEvent(DescriptorEventManager.java:200)
    at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.registerNewObjectClone(UnitOfWorkImpl.java:4216)
    at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.cloneAndRegisterNewObject(RepeatableWriteUnitOfWork.java:576)
    at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalRegisterObject(UnitOfWorkImpl.java:2883)
    at org.eclipse.persistence.internal.sessions.MergeManager.registerObjectForMergeCloneIntoWorkingCopy(MergeManager.java:932)
    at org.eclipse.persistence.internal.sessions.MergeManager.mergeChangesOfCloneIntoWorkingCopy(MergeManager.java:492)
    at org.eclipse.persistence.internal.sessions.MergeManager.mergeChanges(MergeManager.java:263)
    at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.mergeCloneWithReferences(UnitOfWorkImpl.java:3467)
    at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.mergeCloneWithReferences(RepeatableWriteUnitOfWork.java:363)
    at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.mergeCloneWithReferences(UnitOfWorkImpl.java:3427)
    at org.eclipse.persistence.internal.jpa.EntityManagerImpl.mergeInternal(EntityManagerImpl.java:452)
    at org.eclipse.persistence.internal.jpa.EntityManagerImpl.merge(EntityManagerImpl.java:429)
    at com.sun.enterprise.container.common.impl.EntityManagerWrapper.merge(EntityManagerWrapper.java:286)
    at com.lemm.ejb.facade.DoctorsFacade.save(DoctorsFacade.java:61)
    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.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1052)
    at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1124)
    at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:5367)
    at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:619)
    at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:801)
    at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:571)
    at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doAround(SystemInterceptorProxy.java:162)
    at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:144)
    at sun.reflect.GeneratedMethodAccessor78.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:862)
    at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:801)
    at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:371)
    at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:5339)
    at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:5327)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:214)
    ... 47 more

What am I doing wrong? What am I missing?
If it serves for anything heres my persistence.xml

<persistence-unit name="lemmPU" transaction-type="JTA">
    <jta-data-source>jdbc/lemmdb</jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
    </properties>
</persistence-unit>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

冬天的雪花 2024-11-22 23:56:26

该异常清楚地表明存在约束验证违规。我假设您在类中有一个预持久拦截器,它定义了您尝试保存的 ConsultedDoctor 的类型。
查看那里并提供有关类类型和预持久拦截器以及 Medico 实体 bean 的映射和约束的更多信息。

亲切的问候

The exception clearly states that there is a constraint validation violation. I assume you have a pre persist interceptor in the class that defines the type of the consultedDoctor that you are trying to save.
Look there and provide some further info about the type of the class and the pre persist interceptor, as well as the mapping and constraints of the Medico entity beans.

Kind regards

握住我的手 2024-11-22 23:56:26

如果您有一个具有自动递增 Id 的实体,并且您希望使用 JPA 使用其空构造函数来持久化它,则持久化上下文会在 PrePersist 阶段抛出验证错误。请记住,自动递增的 no 是在 postPersist 阶段生成的,因此它会验证实体是否违反空约束。发生这种情况是因为我们在持久性单元中将验证策略指定为 auto。将此验证策略更改为,如

    <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"      
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com 
    /xml/ns/persistence/persistence_2_0.xsd">
    <persistence-unit name="studPU" transaction-type="JTA">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <jta-data-source>jdbc/mysql</jta-data-source>
   <exclude-unlisted-classes>false</exclude-unlisted-classes>
   <validation-mode>NONE</validation-mode>
   <properties>
   <property name="eclipselink.weaving" value="false"/>
   <property name="eclipselink.weaving.fetchgroups" value="false"/>
   </properties>
   </persistence-unit>
    </persistence>

保存持久性单元并重新部署您的应用程序中给出的那样。现在它不会抛出任何验证错误,因为验证的责任在于您。

In case you have an entity with an auto-incremented Id and you want to persist it using JPA using its empty constructor then the persistence context throws validation error in PrePersist stage. Remember the the auto incremented no is generated at postPersist Stage, so it validates the entity as violation of null constraint This happens because we have specified validation strategy in our persistence unit as auto. Change this validation strategy as NONE as given under

    <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"      
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com 
    /xml/ns/persistence/persistence_2_0.xsd">
    <persistence-unit name="studPU" transaction-type="JTA">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <jta-data-source>jdbc/mysql</jta-data-source>
   <exclude-unlisted-classes>false</exclude-unlisted-classes>
   <validation-mode>NONE</validation-mode>
   <properties>
   <property name="eclipselink.weaving" value="false"/>
   <property name="eclipselink.weaving.fetchgroups" value="false"/>
   </properties>
   </persistence-unit>
    </persistence>

save the persistence unit and redeploy your app. Now it wont throw any validation error as the responsibility of validation lies with you.

似梦非梦 2024-11-22 23:56:26

这个问题帮助我在长时间的头撞墙之后解决了这个问题。 @peshkira 是正确的,但如果提供以下代码,它可能会节省我一些时间。对实体运行验证以暴露失败的约束。

ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
Validator validator = factory.getValidator();
Set<ConstraintViolation<Medico>> constraintViolations = validator.validate(medico);
if(constraintViolations.size() > 0){
    Iterator<ConstraintViolation<Medico>> iterator = constraintViolations.iterator();
    while(iterator.hasNext()){
        ConstraintViolation<Medico> cv = iterator.next();
        System.out.println(cv.getMessage());
        System.out.println(cv.getPropertyPath());
    }
 }

我的问题原来是数据库中的现有记录在发现后无法通过实体验证。

This question helped me solve this problem after too many hours of beating my head against the wall. @peshkira is spot on but had the following code been provided it may have saved me some time. Run validation on an entity to expose failing constraint(s).

ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
Validator validator = factory.getValidator();
Set<ConstraintViolation<Medico>> constraintViolations = validator.validate(medico);
if(constraintViolations.size() > 0){
    Iterator<ConstraintViolation<Medico>> iterator = constraintViolations.iterator();
    while(iterator.hasNext()){
        ConstraintViolation<Medico> cv = iterator.next();
        System.out.println(cv.getMessage());
        System.out.println(cv.getPropertyPath());
    }
 }

My problem turned out to be existing records in database that after found could not pass the entity validation.

过潦 2024-11-22 23:56:26

您好,如果您在 Netbeans 中进行开发,您可能会因为一些混淆而遇到此错误,因为 Netbeans 创建了 persistence.xml 文件的两个副本。其中一个您倾向于将其放入类路径中的 META-INF 中,另一个则保留在 Netbeans 的配置文件目录中。在 Netbeans 启动的应用程序上(通过按绿色启动三角形),将使用 META-INF 中的副本,但如果您“清理并构建”项目,则使用配置文件目录中的副本。如果他们不同,地狱就乱了。

Hi if you are developing in Netbeans you may get this error through a a bit of a mix-up because Netbeans creates two copies of persistence.xml file. One of them you tend to put in META-INF in classpath, the other stays in Netbeans' Configuration Files directory. On the app start up by Netbeans (by pressing the green start triangle) the copy from META-INF is used but if you 'clean and build' the project the copy from Configuration Files directory is used. If they differ the hell breaks loose.

花开半夏魅人心 2024-11-22 23:56:26

如果上面提供的帮助没有帮助,请检查您的 servlet 是否在 jsp 页面中获取了正确的参数。

确保 String name =response.getParameter("Name"); (在servlet文件中)jsp文件中存在一个参数“Name”。如果不存在,则将tring name设置为null,并且不能将null插入到标记为not null的字段中。

从个人经验来看。

if the help provided above couldnt help, please check that your servlet is getting the right parameter in your jsp page.

make sure that String name =response.getParameter("Name"); (in servlet file) there exist a parameter "Name" in jsp file. if there exist none,tring name is set to null, and null can't be inserted in a field that is marked with not null.

From personal experience.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文