Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 休眠@Audited conflicts@Version_Java_Spring_Hibernate_Hibernate Envers_Optimistic Locking - Fatal编程技术网

Java 休眠@Audited conflicts@Version

Java 休眠@Audited conflicts@Version,java,spring,hibernate,hibernate-envers,optimistic-locking,Java,Spring,Hibernate,Hibernate Envers,Optimistic Locking,我有一个代码,使用envers,效果很好。我在一个单独的表上进行审计。但后来,我需要使用乐观锁定。但它不适用于@Audited注释。这是我的密码 @MappedSuperclass @Audited public class BaseVO implements IXtrainVO { @Version @Column(name = "Version") private long version; } @Entity @Table(name = "Person") @Au

我有一个代码,使用envers,效果很好。我在一个单独的表上进行审计。但后来,我需要使用乐观锁定。但它不适用于
@Audited
注释。这是我的密码

@MappedSuperclass
@Audited
public class BaseVO implements IXtrainVO
{
    @Version
    @Column(name = "Version")
    private long version;
}

@Entity
@Table(name = "Person")
@Audited
public class PersonVO extends BaseVO
{
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "PersonId", unique = true, nullable = false)
    private Long personId;

    @Column(name = "Name", length = 80, nullable = false)
    @NotBlank
    @Size(max = 80)
    private String name;
}


@Test
public void testLocking() throws Exception
{
    PersonVO person = new PersonVO();
    person.setName( "John" );
    Long personId = personManager.savePerson( person );
    PersonVO copy1 = personManager.findPerson( personId );
    PersonVO copy2 = personManager.findPerson( personId );
    copy1.setName( "John1" );
    personManager.updatePerson( copy1 );
    copy2.setName( "John2" );
    personManager.updatePerson( copy2 );
}
代码应该会引发optimistict锁定错误,但不会。相反,我得到了

原因:java.sql.SQLException:字段“Version”没有默认值。


但是,当我删除
@Audited
注释时,乐观主义就起作用了,我得到了
HibernateOptimisticLockingFailureException
,这正是我所期望的。是否知道这两个注释彼此不协调?我还试着将
@NotAudited
放在版本列上,但仍然不起作用

我能够在中使用讨论解决问题


我需要在db级别上有一个默认值。插入时,没有默认值。但后续更新将增加并检查乐观锁定

我在中使用讨论解决了这个问题

我需要在db级别上有一个默认值。插入时,没有默认值。但后续更新将增加并检查乐观锁定