我正在开发一个项目,它几乎是Affablebean教程的扩展。
我一直在尝试将数据写入数据库,即客户提交表单以购买网站的项目。
来自glassfish服务器日志的错误的关键部分是:‘Unknown column 'CUSTOMER_CustomerID' in 'field list'’
,这是真的,因为实际的列名是‘CustomerOrderID’
。
我试图找出实体框架为什么会生成错误的列名以及问题源自哪里,包括在互联网上查找类似问题。
数据库代码
CREATE TABLE `category` (
`CategoryID` int(11) NOT NULL,
`CategoryName` varchar(50) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='maintains product category details';
CREATE TABLE `customer` (
`CustomerID` int(11) NOT NULL,
`Title` varchar(30) NOT NULL,
`FirstName` varchar(50) NOT NULL,
`LastName` varchar(50) NOT NULL,
`AddressLine1` varchar(60) NOT NULL,
`AddressLine2` varchar(50) NOT NULL,
`City` varchar(50) NOT NULL,
`State` varchar(25) NOT NULL,
`PostCode` varchar(15) NOT NULL,
`Country` varchar(50) NOT NULL,
`Phone` varchar(25) NOT NULL,
`Email` varchar(75) NOT NULL,
`CreditCard` varchar(50) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='maintains customer details';
CREATE TABLE `customer_order` (
`CustomerOrderID` int(11) NOT NULL,
`CustomerID` int(11) NOT NULL,
`ShipperID` int(11) DEFAULT NULL,
`Amount` decimal(6,2) NOT NULL,
`ConfirmationNumber` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='maintains customer order details';
CREATE TABLE `ordered_product` (
`OrderID` int(11) NOT NULL,
`ProductID` int(11) NOT NULL,
`Quantity` smallint(4) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='maintains ordered product details';
CREATE TABLE `product` (
`ProductID` int(11) NOT NULL,
`CategoryID` int(11) NOT NULL,
`SupplierID` int(11) NOT NULL,
`ProductName` varchar(60) NOT NULL,
`Price` decimal(5,2) NOT NULL,
`ProductDescription` varchar(1000) DEFAULT NULL,
`InventoryCount` int(11) NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='maintains product details';
CREATE TABLE `shipper` (
`ShipperID` int(11) NOT NULL,
`CompanyName` varchar(50) NOT NULL,
`ContactFirstName` varchar(50) NOT NULL,
`ContactLastName` varchar(50) NOT NULL,
`ContactTitle` varchar(30) NOT NULL,
`AddressLine1` varchar(60) NOT NULL,
`AddressLine2` varchar(50) NOT NULL,
`City` varchar(50) NOT NULL,
`State` varchar(25) NOT NULL,
`PostCode` varchar(15) NOT NULL,
`Country` varchar(50) NOT NULL,
`Phone` varchar(25) NOT NULL,
`Email` varchar(75) NOT NULL,
`Website` varchar(100) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='maintains dropshipping partner details';
CREATE TABLE `supplier` (
`SupplierID` int(11) NOT NULL,
`CompanyName` varchar(50) NOT NULL,
`ContactFirstName` varchar(50) NOT NULL,
`ContactLastName` varchar(50) NOT NULL,
`ContactTitle` varchar(30) NOT NULL,
`AddressLine1` varchar(60) NOT NULL,
`AddressLine2` varchar(50) NOT NULL,
`City` varchar(50) NOT NULL,
`State` varchar(25) NOT NULL,
`PostCode` varchar(15) NOT NULL,
`Country` varchar(50) NOT NULL,
`Phone` varchar(25) NOT NULL,
`Email` varchar(75) NOT NULL,
`Website` varchar(100) NOT NULL,
`StockLevel` int(11) NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='maintains product supplier details';
订单管理员
@Stateless
@TransactionManagement(TransactionManagementType.CONTAINER)
public class OrderManager {
@PersistenceContext(unitName = "PeripheralsPU")
private EntityManager em;
@Resource
private SessionContext context;
@EJB
private ProductFacade productFacade;
@EJB
private CustomerOrderFacade customerOrderFacade;
@EJB
private OrderedProductFacade orderedProductFacade;
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public int placeOrder(String title, String firstName, String lastName, String addressLine1, String addressLine2, String city, String state, String postCode, String country, String phone, String email, String creditCard, ShoppingCart cart) {
try {
Customer customer = addCustomer(title, firstName, lastName, addressLine1, addressLine2, city, state, postCode, country, phone, email, creditCard);
CustomerOrder order = addOrder(customer, cart);
addOrderedItems(order, cart);
return order.getCustomerOrderID();
} catch (Exception e) {
context.setRollbackOnly();
return 0;
}
}
// Add business logic below. (Right-click in editor and choose
// "Insert Code > Add Business Method")
private Customer addCustomer(String title, String firstName, String lastName, String addressLine1, String addressLine2, String city, String state, String postCode, String country, String phone, String email, String creditCard) {
Customer customer = new Customer();
customer.setTitle(title);
customer.setFirstName(firstName);
customer.setLastName(lastName);
customer.setAddressLine1(addressLine1);
customer.setAddressLine2(addressLine2);
customer.setCity(city);
customer.setState(state);
customer.setPostCode(postCode);
customer.setCountry(country);
customer.setPhone(phone);
customer.setEmail(email);
customer.setCreditCard(creditCard);
em.persist(customer);
return customer;
}
private CustomerOrder addOrder(Customer customer, ShoppingCart cart) {
// Set up customer order
CustomerOrder order = new CustomerOrder();
order.setCustomer(customer);
order.setAmount(BigDecimal.valueOf(cart.getTotal()));
order.setShipperID(null);
// Create confirmation number
Random random = new Random();
int i = random.nextInt(999999999);
order.setConfirmationNumber(i);
out.print(i);
em.persist(order);
return order;
}
private void addOrderedItems(CustomerOrder order, ShoppingCart cart) {
em.flush();
List<ShoppingCartItem> items = cart.getItems();
// Iterate through the shopping cart and create OrderedProducts
for (ShoppingCartItem scItem : items) {
int productId = scItem.getProduct().getProductID();
// set up primary key object
OrderedProductPK orderedProductPK = new OrderedProductPK();
orderedProductPK.setOrderID(order.getCustomerOrderID());
orderedProductPK.setProductID(productId);
// create ordered item using PK object
OrderedProduct orderedItem = new OrderedProduct(orderedProductPK);
// set quantity
orderedItem.setQuantity(scItem.getQuantity());
em.persist(orderedItem);
}
}
}
服务器输出日志
Finer: client acquired: 408549163
Finer: TX binding to tx mgr, status=STATUS_ACTIVE
Finer: acquire unit of work: 343107320
Finest: persist() operation called on: entity.Customer[ customerID=null ].
Finest: persist() operation called on: entity.CustomerOrder[ customerOrderID=null ].
Finer: begin unit of work flush
Finer: TX beginTransaction, status=STATUS_ACTIVE
Finest: Execute query InsertObjectQuery(entity.Customer[ customerID=null ])
Finest: Connection acquired from connection pool [default].
Finest: reconnecting to external connection pool
Fine: INSERT INTO customer (AddressLine1, AddressLine2, City, Country, CreditCard, Email, FirstName, LastName, Phone, PostCode, State, Title) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
bind => [12 parameters bound]
Finest: Execute query ValueReadQuery(name="SEQ_GEN_IDENTITY" sql="SELECT LAST_INSERT_ID()")
Fine: SELECT LAST_INSERT_ID()
Finest: assign sequence to the object (15 -> entity.Customer[ customerID=null ])
Finest: Execute query InsertObjectQuery(entity.CustomerOrder[ customerOrderID=null ])
Fine: INSERT INTO customer_order (Amount, ConfirmationNumber, CustomerID, ShipperID, CUSTOMER_CustomerID) VALUES (?, ?, ?, ?, ?)
bind => [5 parameters bound]
Fine: SELECT 1
Warning: Local Exception Stack:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.1.v20150605-31e8258): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'CUSTOMER_CustomerID' in 'field list'
Error Code: 1054
Call: INSERT INTO customer_order (Amount, ConfirmationNumber, CustomerID, ShipperID, CUSTOMER_CustomerID) VALUES (?, ?, ?, ?, ?)
bind => [5 parameters bound]
Query: InsertObjectQuery(entity.CustomerOrder[ customerOrderID=null ])
at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:331)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(DatabaseAccessor.java:902)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeNoSelect(DatabaseAccessor.java:964)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:633)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:560)
at org.eclipse.persistence.internal.sessions.AbstractSession.basicExecuteCall(AbstractSession.java:2055)
at org.eclipse.persistence.sessions.server.ClientSession.executeCall(ClientSession.java:306)
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.insertObject(DatasourceCallQueryMechanism.java:377)
at org.eclipse.persistence.internal.queries.StatementQueryMechanism.insertObject(StatementQueryMechanism.java:165)
at org.eclipse.persistence.internal.queries.StatementQueryMechanism.insertObject(StatementQueryMechanism.java:180)
at org.eclipse.persistence.internal.queries.DatabaseQueryMechanism.insertObjectForWrite(DatabaseQueryMechanism.java:489)
at org.eclipse.persistence.queries.InsertObjectQuery.executeCommit(InsertObjectQuery.java:80)
at org.eclipse.persistence.queries.InsertObjectQuery.executeCommitWithChangeSet(InsertObjectQuery.java:90)
at org.eclipse.persistence.internal.queries.DatabaseQueryMechanism.executeWriteWithChangeSet(DatabaseQueryMechanism.java:301)
at org.eclipse.persistence.queries.WriteObjectQuery.executeDatabaseQuery(WriteObjectQuery.java:58)
at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:904)
at org.eclipse.persistence.queries.DatabaseQuery.executeInUnitOfWork(DatabaseQuery.java:803)
at org.eclipse.persistence.queries.ObjectLevelModifyQuery.executeInUnitOfWorkObjectLevelModifyQuery(ObjectLevelModifyQuery.java:108)
at org.eclipse.persistence.queries.ObjectLevelModifyQuery.executeInUnitOfWork(ObjectLevelModifyQuery.java:85)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2896)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1857)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1839)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1790)
at org.eclipse.persistence.internal.sessions.CommitManager.commitNewObjectsForClassWithChangeSet(CommitManager.java:227)
at org.eclipse.persistence.internal.sessions.CommitManager.commitAllObjectsForClassWithChangeSet(CommitManager.java:194)
at org.eclipse.persistence.internal.sessions.CommitManager.commitAllObjectsWithChangeSet(CommitManager.java:139)
at org.eclipse.persistence.internal.sessions.AbstractSession.writeAllObjectsWithChangeSet(AbstractSession.java:4260)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitToDatabase(UnitOfWorkImpl.java:1441)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitToDatabaseWithPreBuiltChangeSet(UnitOfWorkImpl.java:1587)
at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.writeChanges(RepeatableWriteUnitOfWork.java:455)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.flush(EntityManagerImpl.java:874)
at com.sun.enterprise.container.common.impl.EntityManagerWrapper.flush(EntityManagerWrapper.java:437)
at session.OrderManager.addOrderedItems(OrderManager.java:131)
at session.OrderManager.placeOrder(OrderManager.java:70)
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:4786)
at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:656)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:608)
at org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:64)
at org.jboss.weld.ejb.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:52)
at sun.reflect.GeneratedMethodAccessor77.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:883)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
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: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:4758)
at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:4746)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:212)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:88)
at com.sun.proxy.$Proxy320.placeOrder(Unknown Source)
at session.__EJB31_Generated__OrderManager__Intf____Bean__.placeOrder(Unknown Source)
at controller.ControllerServlet.doPost(ControllerServlet.java:207)
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.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.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:413)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:283)
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:206)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
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:283)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536)
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:591)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571)
at java.lang.Thread.run(Thread.java:745)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'CUSTOMER_CustomerID' in 'field list'
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
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:1054)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4187)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4119)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2570)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2731)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2815)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2458)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2375)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2359)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(DatabaseAccessor.java:892)
... 100 more
Finer: TX afterCompletion callback, status=ROLLEDBACK
Finest: Connection released to connection pool [default].
Finer: release unit of work
Finer: client released
CustomerOrder
package entity;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
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.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
@Entity
@Table(name = "customer_order")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "CustomerOrder.findAll", query = "SELECT c FROM CustomerOrder c")
, @NamedQuery(name = "CustomerOrder.findByCustomerOrderID", query = "SELECT c FROM CustomerOrder c WHERE c.customerOrderID = :customerOrderID")
, @NamedQuery(name = "CustomerOrder.findByAmount", query = "SELECT c FROM CustomerOrder c WHERE c.amount = :amount")
, @NamedQuery(name = "CustomerOrder.findByConfirmationNumber", query = "SELECT c FROM CustomerOrder c WHERE c.confirmationNumber = :confirmationNumber")})
public class CustomerOrder implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "CustomerOrderID")
private Integer customerOrderID;
// @Max(value=?) @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
@Basic(optional = false)
@NotNull
@Column(name = "Amount")
private BigDecimal amount;
@Basic(optional = false)
@NotNull
@Column(name = "ConfirmationNumber")
private int confirmationNumber;
@JoinColumn(name = "CustomerID", referencedColumnName = "CustomerID")
@ManyToOne(optional = false)
private Customer customerID;
@JoinColumn(name = "ShipperID", referencedColumnName = "ShipperID")
@ManyToOne
private Shipper shipperID;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "customerOrder")
private Collection<OrderedProduct> orderedProductCollection;
private Customer customer;
public CustomerOrder() {
}
public CustomerOrder(Integer customerOrderID) {
this.customerOrderID = customerOrderID;
}
public CustomerOrder(Integer customerOrderID, BigDecimal amount, int confirmationNumber) {
this.customerOrderID = customerOrderID;
this.amount = amount;
this.confirmationNumber = confirmationNumber;
}
public Integer getCustomerOrderID() {
return customerOrderID;
}
public void setCustomerOrderID(Integer customerOrderID) {
this.customerOrderID = customerOrderID;
}
public BigDecimal getAmount() {
return amount;
}
public void setAmount(BigDecimal amount) {
this.amount = amount;
}
public int getConfirmationNumber() {
return confirmationNumber;
}
public void setConfirmationNumber(int confirmationNumber) {
this.confirmationNumber = confirmationNumber;
}
public Customer getCustomerID() {
return customerID;
}
public void setCustomerID(Customer customerID) {
this.customerID = customerID;
}
public Shipper getShipperID() {
return shipperID;
}
public void setShipperID(Shipper shipperID) {
this.shipperID = shipperID;
}
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
@XmlTransient
public Collection<OrderedProduct> getOrderedProductCollection() {
return orderedProductCollection;
}
public void setOrderedProductCollection(Collection<OrderedProduct> orderedProductCollection) {
this.orderedProductCollection = orderedProductCollection;
}
@Override
public int hashCode() {
int hash = 0;
hash += (customerOrderID != null ? customerOrderID.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 CustomerOrder)) {
return false;
}
CustomerOrder other = (CustomerOrder) object;
if ((this.customerOrderID == null && other.customerOrderID != null) || (this.customerOrderID != null && !this.customerOrderID.equals(other.customerOrderID))) {
return false;
}
return true;
}
@Override
public String toString() {
return "entity.CustomerOrder[ customerOrderID=" + customerOrderID + " ]";
}
}