我有一个实体:
import java.io.Serializable;
import java.security.SecureRandom;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.xml.bind.annotation.XmlRootElement;
import br.com.fidellibre.utils.Suporte;
@Entity
public class Cliente implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@SequenceGenerator(name = "SQ_CLIE_SQ_CLIENTE", sequenceName = "SQ_CLIE_SQ_CLIENTE", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SQ_CLIE_SQ_CLIENTE")
@Column(name = "CLIE_SQ_CLIENTE")
private long codigo;
@Column
private String nome;
@Column
private String login;
@Column
private String celular;
@Column
private String email;
@Column
private String codigoGmail;
@Column
private String codigoTwitter;
@Column
private String codigoFacebook;
@Column
private String codigoAparelho;
@Column(name = "CLIE_DT_ULTIMO_ACESSO")
private LocalDateTime ultimoAcesso;
@Column
private String senha;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "cliente")
private List<Conta> contas;
...
}
和一个Converter
:
import java.sql.Timestamp;
import java.time.LocalDateTime;
import javax.persistence.AttributeConverter;
import javax.persistence.Converter;
@Converter(autoApply = true)
public class LocalDateTimeConverter implements AttributeConverter<LocalDateTime, Timestamp> {
@Override
public Timestamp convertToDatabaseColumn(LocalDateTime date) {
return date == null ? null : Timestamp.valueOf(date);
}
@Override
public LocalDateTime convertToEntityAttribute(Timestamp dbData) {
return dbData == null ? null : dbData.toLocalDateTime();
}
}
这在我的单元测试中运行良好,并保留在数据库中。
但是在wildfly 9上,相同的代码崩溃了...... :(
只需修改类,@Converter
像这样注释:
@Column(name = "CLIE_DT_ULTIMO_ACESSO",columnDefinition="TIMESTAMP")
@Convert(converter = LocalDateTimeConverter.class)
private LocalDateTime ultimoAcesso;
autoApply
那么,如果它不是一直有效,那么拥有该属性有什么意义呢?我究竟做错了什么?