我有@Entity
一个
@Entity
@Table(name = "variable")
@XmlRootElement
public class Variable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column(unique = true, nullable = false)
private String name;
@Column
@Enumerated(EnumType.STRING)
private VariableType type;
@Column(nullable = false)
private String units;
@Column
private String description;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "created_on", nullable = false)
private Date createdOn;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "retired_on", nullable = true)
private Date retiredOn;
@Column(nullable = false)
private boolean core;
public Variable(@Nonnull final String name,
@Nonnull final VariableType type,
@Nonnull final String units,
@Nonnull final String description,
@Nonnull final Date createdOn,
@Nonnull final boolean core) {
this.name = name;
this.type = type;
this.units = units;
this.description = description;
this.core = core;
this.createdOn = createdOn;
}
@Nonnull
public long getId() {
return id;
}
@Nonnull
public String getName() {
return name;
}
@Nonnull
public VariableType getType() {
return type;
}
@Nonnull
public String getUnits() {
return units;
}
@Nullable
public String getDescription() {
return description;
}
@Nonnull
public Date getCreatedOn() {
return createdOn;
}
@Nonnull
public Date getRetiredOn() {
return retiredOn;
}
@Nonnull
public boolean isCore() {
return core;
}
@Override
public String toString() {
return new StringBuilder().
append("id="+id+" ").
append("name="+name+" ").
append("type="+type+" ").
append("units="+units+" ").
append("description="+description+" ").
append("createdOn="+createdOn+" ").
append("retiredOn="+retiredOn+" ").
append("core="+core+" ").
toString();
}
}
和 aVariableManager
创建@Entity
实例
public Variable createVariable(@Nonnull final String name,
@Nonnull final VariableType type,
@Nonnull final String units,
@Nonnull final String description,
@Nonnull final boolean core) {
final Variable variable = variableCrudService.create(new Variable(name, type, units, description, new Date(), core));
LOGGER.info("added variable - ", variable);
return variable;
}
当我执行此操作时,我得到的日志信息为
14:18:12,320 INFO [org.jboss.resteasy.cdi.CdiInjectorFactory] (http--127.0.0.1-8080-4) Found BeanManager at java:comp/BeanManager
14:18:13,336 INFO [com.bb.business.VariableManager] (http--127.0.0.1-8080-4) added variable -
我不知道为什么 toString 不打印对象的状态,即使我可以看到变量是在数据库中创建的。