我在Java EE应用程序中从数据库获取数据。
WdLeavesSupplier supplier = entityManager.getEntityManager()
.find(WdLeavesSupplier.class,
Integer.parseInt(supplier_id));
此实体中有一列active
。我已在此处插入了一些数据,这些记录中active
列的值为on
。当我如上所述检索数据时,我的null
列的值为active
。其他列(名称,地址等)值正确。
这样的数据库记录。
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;
实体类Link
实体类代码
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;
}
}
如何解决此错误?