私@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();
}
}
そして、インスタンスVariableManager
を作成します@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がオブジェクトの状態を出力しない理由がわかりません。