1

我有这种情况:

@Entity
@Inheritance(strategy=InheritanceType.JOINED)
@DiscriminatorColumn(name="tipo", discriminatorType=DiscriminatorType.CHAR, length=1)
public class Utente implements Serializable {
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 5)
    @Column(nullable = false, length = 5)
    private String cap;
...

@Entity
@DiscriminatorValue(value="C")
@PrimaryKeyJoinColumn(name="id")
public class Cliente extends Utente implements Serializable {
...

我会更改 Cliente 实例中的“Cap”字段,但是当我尝试这样做时:

Utente u=utenteFacade.find(id);
u.setCap("88888");
utenteFacade.edit(u);

或者

Cliente c=clienteFacade.find(id);
c.setCap("88888");
clienteFacade.edit(u);

但结果不会改变

我收到一个异常:javax.validation.ConstraintViolationException:在对回调事件执行自动 Bean 验证时违反了 Bean 验证约束:'preUpdate'。有关详细信息,请参阅嵌入式 ConstraintViolations。

如果我像这里这样修改实体类的定义,则 utenteFacade.edit(u) 效果很好

@Entity
public class Utente implements Serializable {
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 5)
    @Column(nullable = false, length = 5)
        private String cap;
    ...

    @Entity
    public class Cliente implements Serializable {
    ...
4

0 回答 0