我正在使用JPA API并且效果很好,我尝试在课程中添加新成员/列,当我尝试使用表单向其中添加数据时,它会显示"交易中止"错误。
"javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLIntegrityConstraintViolationException: Column 'ITEM_QTY' cannot accept a NULL value.
Error Code: 20000
Call: INSERT INTO ITEM (B_ID, DESCRIPTION, ITEM_NAME, ITEM_PRICE, MANUFACTURER, DTYPE) VALUES (?, ?, ?, ?, ?, ?)
bind => [6 parameters bound]"
此错误显示在glassfish日志中
这些是我生成的实体 Item_.java
package Entities;
import javax.annotation.Generated;
import javax.persistence.metamodel.SingularAttribute;
import javax.persistence.metamodel.StaticMetamodel;
@Generated(value="EclipseLink-2.5.2.v20140319-rNA", date="2018-03-20T16:09:40")
@StaticMetamodel(Item.class)
public class Item_ {
public static volatile SingularAttribute<Item, Long> item_id;
public static volatile SingularAttribute<Item, Long> b_id;
public static volatile SingularAttribute<Item, Double> item_price;
public static volatile SingularAttribute<Item, String> description;
public static volatile SingularAttribute<Item, String> item_name;
public static volatile SingularAttribute<Item, String> manufacturer;
}
和Scarf.java
package Entities;
import javax.annotation.Generated;
import javax.persistence.metamodel.SingularAttribute;
import javax.persistence.metamodel.StaticMetamodel;
@Generated(value="EclipseLink-2.5.2.v20140319-rNA", date="2018-03-20T16:09:40")
@StaticMetamodel(Scarf.class)
public class Scarf_ extends Item_ {
public static volatile SingularAttribute<Scarf, Long> t_id;
public static volatile SingularAttribute<Scarf, Double> final_price;
public static volatile SingularAttribute<Scarf, Double> discount;
}
EJB&#39; S
Item.java
/*
package Entities;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
/**
* Creates Item Superclass Object
* @author josh
*/
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public class Item implements Serializable {
// Attributes
public static final String ITEM = "Item.findAllItems";
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
public Long item_id;
@Column(nullable = true)
public Long b_id;
@Column(nullable = true)
public String manufacturer;
@Column(nullable = true)
public String item_name;
@Size(max = 2000)
@Column(length = 2000)
public String description;
@Column(nullable = true)
public double item_price;
/**
* Empty Constructor
*/
public Item() {
}
/**
* Constructor with Data
* @param b_id
* @param item_name
* @param manufacturer
* @param description
* @param item_price
*/
public Item(long b_id ,String item_name, String manufacturer, String description, double item_price)
{
this.b_id = b_id;
this.item_name = item_name;
this.manufacturer = manufacturer;
this.description = description;
this.item_price = item_price;
}
/**
* Get and Set Methods
* @return
*/
public Long getId() {
return item_id;
}
public void setId(Long i) {
this.item_id = i;
}
public Long getB_id() {
return b_id;
}
public void setB_id(Long i) {
this.b_id = i;
}
public String getItem_name() {
return item_name;
}
public void setItem_name(String i) {
this.item_name = i;
}
public String getManufacturer() {
return manufacturer;
}
public void setManufacturer(String m) {
this.manufacturer = m;
}
public String getDescription() {
return description;
}
public void setDescription(String d) {
this.description = d;
}
public double getItem_price() {
return item_price;
}
public void setItem_price(double i) {
this.item_price = i;
}
/**
* Search Methods
*/
@Override
public int hashCode() {
int hash = 0;
hash += (item_id != null ? item_id.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object o) {
if (!(o instanceof Item)) {
return false;
}
Item other = (Item) o;
if ((this.item_id == null && other.item_id != null) || (this.item_id != null && !this.item_id.equals(other.item_id))) {
return false;
}
return true;
}
/**
* ToString Override Method
* */
@Override
public String toString() {
return String.format (
"%s%s\n%s%s\n%s%s\n%s%s\n%s%s\n",
"Barcode: ",Long.toString(b_id),
"Item Name: ",this.item_name,
"Manufacturer: ",this.manufacturer,
"Item Price: ",Double.toString(item_price),
"Category: ",this.description
);
}
}
Scarf.java
/*
package Entities;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.validation.constraints.NotNull;
/**
* Creates Scarf Subclass Object
*
*/
@Entity
public class Scarf extends Item implements Serializable
{
// Attributes
public static final String SCARFS = "Scarf.findAllScarfs";
private static final long serialVersionUID = 1L;
@Column(nullable = true)
public long t_id;
@Column(nullable = true)
public double discount;
@Column(nullable = true)
public double final_price;
/**
* Empty Constructor
*/
public Scarf() {
}
/**
* Constructor with Data
* @param b_id
* @param item_name
* @param manufacturer
* @param description
* @param item_price
* @param t_id
* @param discount
* @param final_price
*/
public Scarf(long b_id, String item_name, String manufacturer, String description, double item_price, double discount, double final_price)
{
super(b_id, item_name, manufacturer, description, item_price);
this.t_id = t_id;
this.discount = discount;
this.final_price = final_price;
}
/**
* Get and Set Methods
*
* @return
*/
public Long getT_id() {
return t_id;
}
public void setT_id(Long i) {
this.t_id = i;
}
public double getDiscount() {
return discount;
}
public void setDiscount(double i) {
this.discount = i;
}
public double getFinal_price() {
return final_price;
}
public void setFinal_price(double i) {
this.final_price = i;
}
/**
* ToString Override Method
*/
@Override
public String toString() {
return String.format(
"%s%s\n%s%s\n%s%s\n%s%s\n%s%s\n%s%s\n%s%s\n%s%s\n%s%s\n",
"Item ID: ", Long.toString(this.item_id),
"Barcode: ", Long.toString(this.b_id),
"Item Name: ", this.item_name,
"Manufacturer: ", this.manufacturer,
"Description: ", this.description,
"Item Price: ", Double.toString(item_price),
"Tag ID: ", Long.toString(this.t_id),
"Discount: ", Double.toString(discount),
"Final Price: ", Double.toString(final_price)
);
}
}
Create.xhtml
<h:panelGroup id="messagePanel" layout="block">
<h:messages errorStyle="color: red" infoStyle="color: green" layout="table"/>
</h:panelGroup>
<!--Create panel-->
<h:form>
<h:panelGrid columns="2">
<h:outputLabel value="Barcode" for="b_id" />
<h:inputText id="b_id" value="#{scarfController.selected.b_id}" title="Barcode" required="false" requiredMessage="#{bundle.RequiredMessage}"/>
<h:outputLabel value="Item Name" for="item_name" />
<h:inputText id="item_name" value="#{scarfController.selected.item_name}" title="Item Name" required="true" requiredMessage="#{bundle.RequiredMessage}"/>
<h:outputLabel value="Manufacturer" for="manufacturer" />
<h:inputText id="manufacturer" value="#{scarfController.selected.manufacturer}" title="Manufacturer" required="false" requiredMessage="#{bundle.RequiredMessage}"/>
<h:outputLabel value="Category" for="description" />
<h:inputText id="description" value="#{scarfController.selected.description}" title="Description" required="false" requiredMessage="#{bundle.RequiredMessage}"/>
<h:outputLabel value="Price" for="item_price" />
<h:inputText id="item_price" value="#{scarfController.selected.item_price}" title="Price" required="false" requiredMessage="#{bundle.RequiredMessage}"/>
<h:outputLabel value="Tag Barcode" for="t_id" />
<h:inputText id="t_id" value="#{scarfController.selected.t_id}" title="Tag Barcode" required="false" requiredMessage="#{bundle.RequiredMessage}"/>
<h:outputLabel value="Discount" for="discount" />
<h:inputText id="discount" value="#{scarfController.selected.discount}" title="Discount" required="false" requiredMessage="#{bundle.RequiredMessage}"/>
<h:outputLabel value="Final Price" for="final_price" />
<h:inputText id="final_price" value="#{scarfController.selected.final_price}" title="Final Price" required="false" requiredMessage="#{bundle.RequiredMessage}"/>
</h:panelGrid>
<br/>
<h:commandLink action="#{scarfController.persistScarf}" value="#{bundle.SaveLink}" />
<br />
<a href="/home/" >Cancel</a>
<br />
</h:form>
添加属性后更新日志
Finer: client acquired: 1783508080
Finer: TX binding to tx mgr, status=STATUS_ACTIVE
Finer: acquire unit of work: 2032803813
Finer: TX afterCompletion callback, status=ROLLEDBACK
Finer: release unit of work
Finer: client released
Warning: A system exception occurred during an invocation on EJB ScarfProducer, method: public void Beans.utility.Producer.create(java.lang.Object)
Warning: javax.ejb.EJBException
at com.sun.ejb.containers.EJBContainerTransactionManager.processSystemException(EJBContainerTransactionManager.java:748)
at com.sun.ejb.containers.EJBContainerTransactionManager.completeNewTx(EJBContainerTransactionManager.java:698)
at com.sun.ejb.containers.EJBContainerTransactionManager.postInvokeTx(EJBContainerTransactionManager.java:503)
at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4566)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2074)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2044)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:220)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:88)
at com.sun.proxy.$Proxy233.create(Unknown Source)
at Beans.__EJB31_Generated__ScarfProducer__Intf____Bean__.create(Unknown Source)
at Beans.ScarfController.persistScarf(ScarfController.java:117)
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:498)
at com.sun.el.parser.AstValue.invoke(AstValue.java:289)
at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304)
at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
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:790)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
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:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
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:415)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
at java.lang.Thread.run(Thread.java:748)
答案 0 :(得分:3)
问题是您没有重建/重新部署jar文件。我可以看到它最后一次构建时是aronlilland:receiving_log_api (master)$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
85c7f58994ec receiving_log_api "/bin/sh -c 'bundle …" About an hour ago Up About an hour 0.0.0.0:9292->9292/tcp receiving-log
。在.war文件中, /*
Node is defined as
class Node {
int data;
Node next;
}
*/
Node mergeLists(Node headA, Node headB) {
if(headA==null)
{
return headB;
}
if(headB==null)
{
return headA;
}
if(headA.data<headB.data)
{
headA.next=mergeLists(headA.next,headB.next);
return headA;
}
else{
headB.next=mergeLists(headA.next,headB.next);
return headB;
}
}
中有一个文件公开了这些信息:
Dec 31 17:46:18 AEST 2015
我认为如果您尝试通过maven构建它然后重新部署它,问题就会消失。
答案 1 :(得分:0)
更改数据库表以在ITEM_QTY列上删除非空约束。