更新子实体实例上父类Entity中定义的字段的值

时间:2013-08-01 14:05:07

标签: mysql jpa netbeans

我遇到这种情况:

@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 {
    ...

0 个答案:

没有答案