错误ExceptionMapperStandardImpl与Hibernate一起存在于sql中

时间:2018-08-23 13:35:25

标签: java hibernate ojdbc

在尝试保留Fiscalizacao类时:

@Id
@Column(name = "self_id", columnDefinition = "number")
private Long selfId;
@Null
@Column(columnDefinition = "varchar2(2000 byte)")
private String relatorio;
@NotNull
@ManyToOne(cascade = { CascadeType.DETACH, CascadeType.PERSIST, CascadeType.REFRESH,
        CascadeType.REMOVE }, fetch = FetchType.LAZY)
@JsonIgnoreProperties({ "hibernateLazyInitializer", "handler" })
@JoinColumn(name = "tipo_grau_aproveitamento_id", columnDefinition = "number")
private TipoGrauAproveitamento tipoGrauAproveitamento;
@NotNull
@ManyToOne(cascade = { CascadeType.DETACH, CascadeType.PERSIST, CascadeType.REFRESH,
        CascadeType.REMOVE }, fetch = FetchType.LAZY)
@JsonIgnoreProperties({ "hibernateLazyInitializer", "handler" })
@JoinColumn(name = "tipo_medida_id", columnDefinition = "number")
private TipoMedida tipoMedida;
@Null
@ManyToOne(cascade = { CascadeType.DETACH, CascadeType.PERSIST, CascadeType.REFRESH,
        CascadeType.REMOVE }, fetch = FetchType.LAZY)
@JsonIgnore
@JsonProperty(access = Access.READ_ONLY)
@JoinColumns({ @JoinColumn(name = "plano_id", referencedColumnName = "self_id"),
        @JoinColumn(name = "processo_id", referencedColumnName = "processo_id") })
private PlanoFiscalizacaoProcesso plano;
@Null
@ManyToOne(cascade = { CascadeType.DETACH, CascadeType.PERSIST, CascadeType.REFRESH,
        CascadeType.REMOVE }, fetch = FetchType.LAZY)
@JsonIgnore
@JoinColumn(name = "reparticao_id", columnDefinition = "number")
@NotFound(action = NotFoundAction.IGNORE)
private Reparticao reparticao;
@Null
@Column(name = "data_fiscalizacao", columnDefinition = "date")
private Date dataFiscalizacao;
@ManyToOne(cascade = { CascadeType.DETACH, CascadeType.PERSIST, CascadeType.REFRESH,
        CascadeType.REMOVE }, fetch = FetchType.LAZY)
@JsonIgnore
@JoinColumn(name = "status_sync", referencedColumnName = "status", columnDefinition = "varchar2(1 byte)")
private SyncStatus status_sync;
@Null
@Column(name = "version_date", columnDefinition = "date")
private Date versionDate;

我收到以下错误:

[Validation failed for classes [mz.co.sigit.teste.fiscalizacao.plano.processo.fiscalizacao.Fiscalizacao] during persist time for groups [javax.validation.groups.Default, ]
List of constraint violations:[
ConstraintViolationImpl{interpolatedMessage='must be null', propertyPath=plano, rootBeanClass=class mz.co.sigit.teste.fiscalizacao.plano.processo.fiscalizacao.Fiscalizacao, messageTemplate='{javax.validation.constraints.Null.message}'}
ConstraintViolationImpl{interpolatedMessage='must be null', propertyPath=dataFiscalizacao, rootBeanClass=class mz.co.sigit.teste.fiscalizacao.plano.processo.fiscalizacao.Fiscalizacao, messageTemplate='{javax.validation.constraints.Null.message}'}
ConstraintViolationImpl{interpolatedMessage='must be null', propertyPath=relatorio, rootBeanClass=class mz.co.sigit.teste.fiscalizacao.plano.processo.fiscalizacao.Fiscalizacao, messageTemplate='{javax.validation.constraints.Null.message}'}]]

我不明白为什么插入的消息提示约束违例列表中的字段必须为空。

我使用了注释@Null,因此数据库字段属性可以接受NULL值。尽管没有null值被传递到这些字段。

例如,JSON中的plano字段:

"plano" : {
"planoFiscalizacao" : {
  "dataPrevisaoFim" : "2018-09-03T09:00:00.000+0200",
  "dataPrevisaoInicio" : "2018-08-03T09:00:00.000+0200",
  "selfId" : 201000000291,
  "loaded" : true,
  "managed" : false,
  "valid" : true
}

1 个答案:

答案 0 :(得分:0)

要在数据库中允许空值,您必须具有:

@Column(nullable = true)

@Null根据JSR-303检查值是否为空