Java 在mysql中返回null而不是列值
我在JavaEE应用程序中从数据库中获取数据,如下所示Java 在mysql中返回null而不是列值,java,mysql,jpa,entitymanager,Java,Mysql,Jpa,Entitymanager,我在JavaEE应用程序中从数据库中获取数据,如下所示 WdLeavesSupplier supplier = entityManager.getEntityManager() .find(WdLeavesSupplier.class, Integer.parseInt(supplier_id)); 此实体中有一列处于活动状态。我已经在其中插入了一些数据,活动列的值在这些记录中为on。当我像上面那个样检索数据时,我将null作为活动列的值。其他栏
WdLeavesSupplier supplier = entityManager.getEntityManager()
.find(WdLeavesSupplier.class,
Integer.parseInt(supplier_id));
此实体中有一列处于活动状态。我已经在其中插入了一些数据,活动列的值在这些记录中为on。当我像上面那个样检索数据时,我将null作为活动列的值。其他栏目名称、地址等。。正确获取值
像这样的数据库记录
supplier_id, supplier_code, supplier_first_name, supplier_last_name, supplier_phone, supplier_address_a, supplier_address_b, center_id, active, comment, created_date
14, 't1', 'Mark', 'Smith', '0711234224', 'g45, new town', 'Galle', 41, 'on', 'test comment', '2014-06-24 17:06:38'
下面是表格结构
CREATE TABLE `wdtccdb`.`wd_leaves_supplier` (
`supplier_id` int(10) unsigned NOT NULL auto_increment,
`supplier_code` varchar(45) NOT NULL default '',
`supplier_first_name` varchar(45) NOT NULL default '',
`supplier_last_name` varchar(45) default NULL,
`supplier_phone` varchar(45) default NULL,
`supplier_address_a` varchar(45) default NULL,
`supplier_address_b` varchar(45) default NULL,
`center_id` int(10) unsigned NOT NULL default '0',
`active` varchar(5) default NULL,
`comment` varchar(100) default NULL,
`created_date` timestamp NOT NULL default CURRENT_TIMESTAMP,
PRIMARY KEY (`supplier_id`),
UNIQUE KEY `supp_code_un` (`supplier_code`),
KEY `FK_wd_leaves_supplier_center_id` (`center_id`),
CONSTRAINT `FK_wd_leaves_supplier_center_id` FOREIGN KEY (`center_id`) REFERENCES `wd_collection_center` (`center_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
实体类
实体类代码
如何修复此错误?从共享实体代码开始。@jbniset问题已更新为实体类的链接。这听起来像个愚蠢的问题,但它是否已在数据库中设置?因为此列的默认字段为空。你能把你的问题附加到你想从数据库中得到的那一行吗?把你的代码贴在这里。不在dropbox上。@JBNizet它有170行。好的,我把它贴在这里。
package com.wd.entity;
import java.io.Serializable;
import javax.persistence.*;
import java.sql.Timestamp;
import java.util.List;
/**
* The persistent class for the wd_leaves_supplier database table.
*
*/
@Entity
@Table(name = "wd_leaves_supplier")
@NamedQueries({
@NamedQuery(name = "WdLeavesSupplier.findAll", query = "SELECT u FROM WdLeavesSupplier u"),
@NamedQuery(name = "WdLeavesSupplier.findByCode", query = "SELECT u FROM WdLeavesSupplier u WHERE u.supplierCode = :code") })
public class WdLeavesSupplier implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "supplier_id")
private int supplierId;
private String active;
private String comment;
@Column(name = "created_date")
private Timestamp createdDate;
@Column(name = "supplier_address_a")
private String supplierAddressA;
@Column(name = "supplier_address_b")
private String supplierAddressB;
@Column(name = "supplier_code")
private String supplierCode;
@Column(name = "supplier_first_name")
private String supplierFirstName;
@Column(name = "supplier_last_name")
private String supplierLastName;
@Column(name = "supplier_phone")
private String supplierPhone;
// bi-directional many-to-one association to WdLeafPurchase
@OneToMany(mappedBy = "wdLeavesSupplier")
private List<WdLeafPurchase> wdLeafPurchases;
// bi-directional many-to-one association to WdCollectionCenter
@ManyToOne
@JoinColumn(name = "center_id")
private WdCollectionCenter wdCollectionCenter;
// bi-directional many-to-one association to WdSupplierLoan
@OneToMany(mappedBy = "wdLeavesSupplier")
private List<WdSupplierLoan> wdSupplierLoans;
public WdLeavesSupplier() {
}
public int getSupplierId() {
return this.supplierId;
}
public void setSupplierId(int supplierId) {
this.supplierId = supplierId;
}
public String getActive() {
return this.active;
}
public void setActive(String active) {
this.active = active;
}
public String getComment() {
return this.comment;
}
public void setComment(String comment) {
this.comment = comment;
}
public Timestamp getCreatedDate() {
return this.createdDate;
}
public void setCreatedDate(Timestamp createdDate) {
this.createdDate = createdDate;
}
public String getSupplierAddressA() {
return this.supplierAddressA;
}
public void setSupplierAddressA(String supplierAddressA) {
this.supplierAddressA = supplierAddressA;
}
public String getSupplierAddressB() {
return this.supplierAddressB;
}
public void setSupplierAddressB(String supplierAddressB) {
this.supplierAddressB = supplierAddressB;
}
public String getSupplierCode() {
return this.supplierCode;
}
public void setSupplierCode(String supplierCode) {
this.supplierCode = supplierCode;
}
public String getSupplierFirstName() {
return this.supplierFirstName;
}
public void setSupplierFirstName(String supplierFirstName) {
this.supplierFirstName = supplierFirstName;
}
public String getSupplierLastName() {
return this.supplierLastName;
}
public void setSupplierLastName(String supplierLastName) {
this.supplierLastName = supplierLastName;
}
public String getSupplierPhone() {
return this.supplierPhone;
}
public void setSupplierPhone(String supplierPhone) {
this.supplierPhone = supplierPhone;
}
public List<WdLeafPurchase> getWdLeafPurchases() {
return this.wdLeafPurchases;
}
public void setWdLeafPurchases(List<WdLeafPurchase> wdLeafPurchases) {
this.wdLeafPurchases = wdLeafPurchases;
}
public WdCollectionCenter getWdCollectionCenter() {
return this.wdCollectionCenter;
}
public void setWdCollectionCenter(WdCollectionCenter wdCollectionCenter) {
this.wdCollectionCenter = wdCollectionCenter;
}
public List<WdSupplierLoan> getWdSupplierLoans() {
return this.wdSupplierLoans;
}
public void setWdSupplierLoans(List<WdSupplierLoan> wdSupplierLoans) {
this.wdSupplierLoans = wdSupplierLoans;
}
}