em.remove不起作用,输出错误非常令人惊讶,因为它说我从另一个实体中选择,你可以在下面看到我不是。
以下是代码:
public void deleteAppointment(int appointmentID, int staffID) {
try {
StaffApointmentsPK staffApointmentsPK = new StaffApointmentsPK();
staffApointmentsPK.setAppointmentId(appointmentID);
staffApointmentsPK.setStaffId(staffID);
StaffApointments staffApointments = staffApointmentsFacade.find(staffApointmentsPK);
em.merge(staffApointments);
em.remove(staffApointments);
em.flush();
System.out.println("natapos");
} catch (Exception e) {
System.out.println("Exception in appointmentmanager " + e);
}
}
这是错误:
INFO: Exception in Application Controller java.lang.NullPointerException
INFO: prepare a page to handle this
INFO: appointmentIDBeingManaged 1000013
INFO: sstaffIDPrevious 1000036
INFO: sstaffID current1000036
WARNING: Local Exception Stack:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'blood' in 'field list'
Error Code: 1054
Call: SELECT id, blood pressure, complaint, diagnosis, height, temperature, treatment, weight, staff_apointments_appointment_id, staff_apointments_staff_id FROM itr WHERE ((staff_apointments_staff_id = ?) AND (staff_apointments_appointment_id = ?))
bind => [2 parameters bound]
Query: ReadAllQuery(name="itrCollection" referenceClass=Itr sql="SELECT id, blood pressure, complaint, diagnosis, height, temperature, treatment, weight, staff_apointments_appointment_id, staff_apointments_staff_id FROM itr WHERE ((staff_apointments_staff_id = ?) AND (staff_apointments_appointment_id = ?))")
at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:340)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:679)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:558)
at org.eclipse.persistence.internal.sessions.AbstractSession.basicExecuteCall(AbstractSession.java:1995)
at org.eclipse.persistence.sessions.server.ServerSession.executeCall(ServerSession.java:570)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:242)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:228)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeSelectCall(DatasourceCallQueryMechanism.java:299)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.selectAllRows(DatasourceCallQueryMechanism.java:694)
at org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllRowsFromTable(ExpressionQueryMechanism.java:2714)
at org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllRows(ExpressionQueryMechanism.java:2667)
at org.eclipse.persistence.queries.ReadAllQuery.executeObjectLevelReadQuery(ReadAllQuery.java:477)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeDatabaseQuery(ObjectLevelReadQuery.java:1155)
at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:899)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:1114)
at org.eclipse.persistence.queries.ReadAllQuery.execute(ReadAllQuery.java:402)
at org.eclipse.persistence.internal.sessions.AbstractSession.internalExecuteQuery(AbstractSession.java:3207)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1797)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1779)
at org.eclipse.persistence.internal.indirection.QueryBasedValueHolder.instantiate(QueryBasedValueHolder.java:115)
at org.eclipse.persistence.internal.indirection.QueryBasedValueHolder.instantiate(QueryBasedValueHolder.java:102)
at org.eclipse.persistence.internal.indirection.DatabaseValueHolder.getValue(DatabaseValueHolder.java:88)
at org.eclipse.persistence.internal.indirection.UnitOfWorkValueHolder.instantiateImpl(UnitOfWorkValueHolder.java:165)
at org.eclipse.persistence.internal.indirection.UnitOfWorkValueHolder.instantiate(UnitOfWorkValueHolder.java:226)
at org.eclipse.persistence.internal.indirection.DatabaseValueHolder.getValue(DatabaseValueHolder.java:88)
at org.eclipse.persistence.indirection.IndirectList.buildDelegate(IndirectList.java:252)
at org.eclipse.persistence.indirection.IndirectList.getDelegate(IndirectList.java:423)
at org.eclipse.persistence.indirection.IndirectList$1.<init>(IndirectList.java:551)
at org.eclipse.persistence.indirection.IndirectList.listIterator(IndirectList.java:550)
at org.eclipse.persistence.indirection.IndirectList.iterator(IndirectList.java:514)
at org.eclipse.persistence.internal.queries.CollectionContainerPolicy.iteratorFor(CollectionContainerPolicy.java:150)
at org.eclipse.persistence.mappings.CollectionMapping.cascadePerformRemoveIfRequired(CollectionMapping.java:352)
at org.eclipse.persistence.internal.descriptors.ObjectBuilder.cascadePerformRemove(ObjectBuilder.java:2143)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.performRemove(UnitOfWorkImpl.java:3597)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.remove(EntityManagerImpl.java:563)
at com.sun.enterprise.container.common.impl.EntityManagerWrapper.remove(EntityManagerWrapper.java:323)
at session.managers.AppointmentManager.deleteAppointment(AppointmentManager.java:143)
at session.managers.AppointmentManager.editAppointment(AppointmentManager.java:158)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
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:4695)
at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:630)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:582)
at org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:46)
at sun.reflect.GeneratedMethodAccessor76.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:883)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:582)
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.GeneratedMethodAccessor77.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:883)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:369)
at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:4667)
at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:4655)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:212)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:88)
at com.sun.proxy.$Proxy2061.editAppointment(Unknown Source)
at session.managers.__EJB31_Generated__AppointmentManager__Intf____Bean__.editAppointment(Unknown Source)
at actions.patient.appointment.EditAppointmentAction.execute(EditAppointmentAction.java:64)
at controller.ApplicationController.processRequest(ApplicationController.java:36)
at controller.ControllerServlet.process(ControllerServlet.java:42)
at controller.ControllerServlet.doPost(ControllerServlet.java:68)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:344)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at filter.SessionTimeoutFilter.doFilter(SessionTimeoutFilter.java:49)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:316)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:357)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:188)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
at java.lang.Thread.run(Thread.java:744)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'blood' in 'field list'
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1053)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4120)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4052)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2503)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2664)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2794)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2322)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeSelect(DatabaseAccessor.java:1002)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:641)
... 105 more
INFO: Exception in appointmentmanager Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'blood' in 'field list'
Error Code: 1054
Call: SELECT id, blood pressure, complaint, diagnosis, height, temperature, treatment, weight, staff_apointments_appointment_id, staff_apointments_staff_id FROM itr WHERE ((staff_apointments_staff_id = ?) AND (staff_apointments_appointment_id = ?))
bind => [2 parameters bound]
Query: ReadAllQuery(name="itrCollection" referenceClass=Itr sql="SELECT id, blood pressure, complaint, diagnosis, height, temperature, treatment, weight, staff_apointments_appointment_id, staff_apointments_staff_id FROM itr WHERE ((staff_apointments_staff_id = ?) AND (staff_apointments_appointment_id = ?))")
为什么在我尝试删除/删除数据时从ITR实体中进行选择。任何人都可以帮助我吗?
编辑1:
很抱歉没有为每个人发布我的实体,以便能够看到我的情景更清晰。
以下是ITR实体:
public class Itr implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id")
private Integer id;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 255)
@Column(name = "complaint")
private String complaint;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 255)
@Column(name = "diagnosis")
private String diagnosis;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 255)
@Column(name = "treatment")
private String treatment;
// @Max(value=?) @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
@Column(name = "height")
private BigDecimal height;
@Column(name = "weight")
private BigDecimal weight;
@Column(name = "temperature")
private BigDecimal temperature;
@Size(max = 10)
@Column(name = "blood pressure")
private String bloodPressure;
@JoinColumns({
@JoinColumn(name = "staff_apointments_appointment_id", referencedColumnName = "appointment_id"),
@JoinColumn(name = "staff_apointments_staff_id", referencedColumnName = "staff_id")})
@ManyToOne(optional = false)
private StaffApointments staffApointments;
public Itr() {
}
public Itr(Integer id) {
this.id = id;
}
public Itr(Integer id, String complaint, String diagnosis, String treatment) {
this.id = id;
this.complaint = complaint;
this.diagnosis = diagnosis;
this.treatment = treatment;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getComplaint() {
return complaint;
}
public void setComplaint(String complaint) {
this.complaint = complaint;
}
public String getDiagnosis() {
return diagnosis;
}
public void setDiagnosis(String diagnosis) {
this.diagnosis = diagnosis;
}
public String getTreatment() {
return treatment;
}
public void setTreatment(String treatment) {
this.treatment = treatment;
}
public BigDecimal getHeight() {
return height;
}
public void setHeight(BigDecimal height) {
this.height = height;
}
public BigDecimal getWeight() {
return weight;
}
public void setWeight(BigDecimal weight) {
this.weight = weight;
}
public BigDecimal getTemperature() {
return temperature;
}
public void setTemperature(BigDecimal temperature) {
this.temperature = temperature;
}
public String getBloodPressure() {
return bloodPressure;
}
public void setBloodPressure(String bloodPressure) {
this.bloodPressure = bloodPressure;
}
public StaffApointments getStaffApointments() {
return staffApointments;
}
public void setStaffApointments(StaffApointments staffApointments) {
this.staffApointments = staffApointments;
}
@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.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 Itr)) {
return false;
}
Itr other = (Itr) object;
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false;
}
return true;
}
@Override
public String toString() {
return "entity.Itr[ id=" + id + " ]";
}
}
这是StaffApointments实体:
@Entity
@Table(name = "staff_apointments")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "StaffApointments.findAll", query = "SELECT s FROM StaffApointments s"),
@NamedQuery(name = "StaffApointments.findByAppointmentId", query = "SELECT s FROM StaffApointments s WHERE s.staffApointmentsPK.appointmentId = :appointmentId"),
@NamedQuery(name = "StaffApointments.findByStaffId", query = "SELECT s FROM StaffApointments s WHERE s.staffApointmentsPK.staffId = :staffId"),
@NamedQuery(name = "StaffApointments.findByTime", query = "SELECT s FROM StaffApointments s WHERE s.time = :time"),
@NamedQuery(name = "StaffApointments.findByLocation", query = "SELECT s FROM StaffApointments s WHERE s.location = :location"),
@NamedQuery(name = "StaffApointments.findByType", query = "SELECT s FROM StaffApointments s WHERE s.type = :type"),
@NamedQuery(name = "StaffApointments.findByStatus", query = "SELECT s FROM StaffApointments s WHERE s.status = :status")})
public class StaffApointments implements Serializable {
private static final long serialVersionUID = 1L;
@EmbeddedId
protected StaffApointmentsPK staffApointmentsPK;
@Column(name = "time")
@Temporal(TemporalType.TIME)
private Date time;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 45)
@Column(name = "location")
private String location;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 45)
@Column(name = "type")
private String type;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 20)
@Column(name = "status")
private String status;
@JoinColumn(name = "appointment_id", referencedColumnName = "id", insertable = false, updatable = false)
@ManyToOne(optional = false)
private Appointment appointment;
@JoinColumn(name = "staff_id", referencedColumnName = "id", insertable = false, updatable = false)
@ManyToOne(optional = false)
private Staff staff;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "staffApointments")
private Collection<Itr> itrCollection;
public StaffApointments() {
}
public StaffApointments(StaffApointmentsPK staffApointmentsPK) {
this.staffApointmentsPK = staffApointmentsPK;
}
public StaffApointments(StaffApointmentsPK staffApointmentsPK, String location, String type, String status) {
this.staffApointmentsPK = staffApointmentsPK;
this.location = location;
this.type = type;
this.status = status;
}
public StaffApointments(int appointmentId, int staffId) {
this.staffApointmentsPK = new StaffApointmentsPK(appointmentId, staffId);
}
public StaffApointmentsPK getStaffApointmentsPK() {
return staffApointmentsPK;
}
public void setStaffApointmentsPK(StaffApointmentsPK staffApointmentsPK) {
this.staffApointmentsPK = staffApointmentsPK;
}
public Date getTime() {
return time;
}
public void setTime(Date time) {
this.time = time;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public Appointment getAppointment() {
return appointment;
}
public void setAppointment(Appointment appointment) {
this.appointment = appointment;
}
public Staff getStaff() {
return staff;
}
public void setStaff(Staff staff) {
this.staff = staff;
}
@XmlTransient
public Collection<Itr> getItrCollection() {
return itrCollection;
}
public void setItrCollection(Collection<Itr> itrCollection) {
this.itrCollection = itrCollection;
}
@Override
public int hashCode() {
int hash = 0;
hash += (staffApointmentsPK != null ? staffApointmentsPK.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 StaffApointments)) {
return false;
}
StaffApointments other = (StaffApointments) object;
if ((this.staffApointmentsPK == null && other.staffApointmentsPK != null) || (this.staffApointmentsPK != null && !this.staffApointmentsPK.equals(other.staffApointmentsPK))) {
return false;
}
return true;
}
@Override
public String toString() {
return "entity.StaffApointments[ staffApointmentsPK=" + staffApointmentsPK + " ]";
}
}
ITR
引用staffapointments的复合主键