@Version注解不起作用

huangapple go评论73阅读模式
英文:

@Version annotation does not work correctly

问题

我在Spring Boot项目中使用Java Persistence版本控制来处理乐观并发控制。我有3个模型:Process(流程)、Amazing(令人惊奇的)和Contract(合同)。

Process(流程):

@Entity
@Table(name = "processes")
class Process(

...
...
  @Version
  private var version: Int = 0

)

Amazing(令人惊奇的):

@Entity
@Table(name = "amazing")
class Amazing(

        @JsonIgnore
        @ManyToOne
        @JoinColumn(name = "process_id")
        var process: Process

...
...
)

Contract(合同):

@Entity
@Table(name = "Contracts")
class Contract(

        @JsonIgnore
        @ManyToOne
        @JoinColumn(name = "process_id")
        var process: Process

...
...
)

现在,我想从数据库中检索数据。首先,我调用了流程(process),然后调用了令人惊奇的(amazing)和合同(contracts)的列表。问题是,当我调用第二个列表时,流程的版本号增加了!

val process = processRepo.findById(processId) //版本号为20
val contracts = contractRepo.findAll() //版本号为20
val amazing = amazingRepo.findAll() //版本号为21

ContractRepo(合同仓库):

interface ContractRepo : JpaRepository<Contract, Long>

AmazingRepo(令人惊奇的仓库):

interface AmazingRepo : JpaRepository<Amazing, Long>

我无法找到在未保存流程的情况下为什么在第二次调用时版本号会增加的问题。

注意:
我启用了SQL日志。所有被记录的内容都是SELECT查询。

英文:

I use Java Persistence versioning in Spring Boot project for handling optimistic concurrency control.

I have 3 model: Process, Amazing and Contract.

Process

@Entity
@Table(name = &quot;processes&quot;)
class Process(

...
...
  @Version
  private var version: Int = 0

)

Amazing

@Entity
@Table(name = &quot;amazing&quot;)
class Amazing(

        @JsonIgnore
        @ManyToOne
        @JoinColumn(name = &quot;process_id&quot;)
        var process: Process

...
...
)

Contract

@Entity
@Table(name = &quot;Contracts&quot;)
class Contract(

        @JsonIgnore
        @ManyToOne
        @JoinColumn(name = &quot;process_id&quot;)
        var process: Process

...
...
)

Now I want retrieve data from database. First, I call process, then call list of amazing and contracts. The problem is when I call second list, version of process is incremented!

val process = processRepo.findById(processId) //version is 20
val contracts = contractRepo.findAll() //version is 20
val amazing = amazingRepo.findAll() //version is 21

ContractRepo

interface ContractRepo : JpaRepository&lt;Contract, Long&gt;

AmazingRepo

interface AmazingRepo : JpaRepository&lt;Amazing, Long&gt;

I cannot find the problem why version is incremented in second call without save process?

Notice:
I enable SQL log. All that is logged are selects.

Hibernate: select fixedamazi0_.id as id1_8_, fixedamazi0_.action_date as action_d2_8_, fixedamazi0_.amount as amount3_8_, fixedamazi0_.created_at as created_4_8_, fixedamazi0_.employee_id as employee9_8_, fixedamazi0_.expiration_date as expirati5_8_, fixedamazi0_.modified_at as modified6_8_, fixedamazi0_.percent as percent7_8_, fixedamazi0_.process_id as process10_8_, fixedamazi0_.row_code as row_code8_8_ from fixed_amazing fixedamazi0_
Hibernate: select employee0_.id as id1_7_0_, employee0_.company_id as company_9_7_0_, employee0_.created_at as created_2_7_0_, employee0_.isargari_type as isargari3_7_0_, employee0_.modified_at as modified4_7_0_, employee0_.personnel_id as personne5_7_0_, employee0_.roles as roles6_7_0_, employee0_.status as status7_7_0_, employee0_.type as type8_7_0_, employee0_.user_id as user_id10_7_0_, company1_.id as id1_2_1_, company1_.areas as areas2_2_1_, company1_.company_code as company_3_2_1_, company1_.created_at as created_4_2_1_, company1_.direction as directio5_2_1_, company1_.financial_code as financia6_2_1_, company1_.modified_at as modified7_2_1_, company1_.name as name8_2_1_, company1_.parent_id as parent_11_2_1_, company1_.province as province9_2_1_, company1_.zone as zone10_2_1_, company2_.id as id1_2_2_, company2_.areas as areas2_2_2_, company2_.company_code as company_3_2_2_, company2_.created_at as created_4_2_2_, company2_.direction as directio5_2_2_, company2_.financial_code as financia6_2_2_, company2_.modified_at as modified7_2_2_, company2_.name as name8_2_2_, company2_.parent_id as parent_11_2_2_, company2_.province as province9_2_2_, company2_.zone as zone10_2_2_, user3_.id as id1_24_3_, user3_.birth_date as birth_da2_24_3_, user3_.created_at as created_3_24_3_, user3_.email as email4_24_3_, user3_.father_name as father_n5_24_3_, user3_.first_name as first_na6_24_3_, user3_.gender as gender7_24_3_, user3_.isargari_type as isargari8_24_3_, user3_.last_name as last_nam9_24_3_, user3_.marital_state as marital10_24_3_, user3_.modified_at as modifie11_24_3_, user3_.national_code as nationa12_24_3_, user3_.password as passwor13_24_3_, user3_.personnel_id as personn14_24_3_, user3_.phone as phone15_24_3_, user3_.sso_validation as sso_val16_24_3_, user3_.telephone as telepho17_24_3_, user3_.version as version18_24_3_ from employees employee0_ left outer join companies company1_ on employee0_.company_id=company1_.id left outer join companies company2_ on company1_.parent_id=company2_.id left outer join users user3_ on employee0_.user_id=user3_.id where employee0_.id=?
Hibernate: select payrollpro0_.id as id1_19_0_, payrollpro0_.comments as comments2_19_0_, payrollpro0_.company_id as company_8_19_0_, payrollpro0_.created_at as created_3_19_0_, payrollpro0_.modified_at as modified4_19_0_, payrollpro0_.period_id as period_i9_19_0_, payrollpro0_.state as state5_19_0_, payrollpro0_.type as type6_19_0_, payrollpro0_.version as version7_19_0_, company1_.id as id1_2_1_, company1_.areas as areas2_2_1_, company1_.company_code as company_3_2_1_, company1_.created_at as created_4_2_1_, company1_.direction as directio5_2_1_, company1_.financial_code as financia6_2_1_, company1_.modified_at as modified7_2_1_, company1_.name as name8_2_1_, company1_.parent_id as parent_11_2_1_, company1_.province as province9_2_1_, company1_.zone as zone10_2_1_, company2_.id as id1_2_2_, company2_.areas as areas2_2_2_, company2_.company_code as company_3_2_2_, company2_.created_at as created_4_2_2_, company2_.direction as directio5_2_2_, company2_.financial_code as financia6_2_2_, company2_.modified_at as modified7_2_2_, company2_.name as name8_2_2_, company2_.parent_id as parent_11_2_2_, company2_.province as province9_2_2_, company2_.zone as zone10_2_2_, payperiod3_.id as id1_15_3_, payperiod3_.code as code2_15_3_, payperiod3_.created_at as created_3_15_3_, payperiod3_.days_count as days_cou4_15_3_, payperiod3_.end_date as end_date5_15_3_, payperiod3_.modified_at as modified6_15_3_, payperiod3_.name as name7_15_3_, payperiod3_.persian_end_date as persian_8_15_3_, payperiod3_.persian_start_date as persian_9_15_3_, payperiod3_.start_date as start_d10_15_3_ from payroll_process_managements payrollpro0_ left outer join companies company1_ on payrollpro0_.company_id=company1_.id left outer join companies company2_ on company1_.parent_id=company2_.id left outer join pay_periods payperiod3_ on payrollpro0_.period_id=payperiod3_.id where payrollpro0_.id=?
Hibernate: select employee0_.id as id1_7_0_, employee0_.company_id as company_9_7_0_, employee0_.created_at as created_2_7_0_, employee0_.isargari_type as isargari3_7_0_, employee0_.modified_at as modified4_7_0_, employee0_.personnel_id as personne5_7_0_, employee0_.roles as roles6_7_0_, employee0_.status as status7_7_0_, employee0_.type as type8_7_0_, employee0_.user_id as user_id10_7_0_, company1_.id as id1_2_1_, company1_.areas as areas2_2_1_, company1_.company_code as company_3_2_1_, company1_.created_at as created_4_2_1_, company1_.direction as directio5_2_1_, company1_.financial_code as financia6_2_1_, company1_.modified_at as modified7_2_1_, company1_.name as name8_2_1_, company1_.parent_id as parent_11_2_1_, company1_.province as province9_2_1_, company1_.zone as zone10_2_1_, company2_.id as id1_2_2_, company2_.areas as areas2_2_2_, company2_.company_code as company_3_2_2_, company2_.created_at as created_4_2_2_, company2_.direction as directio5_2_2_, company2_.financial_code as financia6_2_2_, company2_.modified_at as modified7_2_2_, company2_.name as name8_2_2_, company2_.parent_id as parent_11_2_2_, company2_.province as province9_2_2_, company2_.zone as zone10_2_2_, user3_.id as id1_24_3_, user3_.birth_date as birth_da2_24_3_, user3_.created_at as created_3_24_3_, user3_.email as email4_24_3_, user3_.father_name as father_n5_24_3_, user3_.first_name as first_na6_24_3_, user3_.gender as gender7_24_3_, user3_.isargari_type as isargari8_24_3_, user3_.last_name as last_nam9_24_3_, user3_.marital_state as marital10_24_3_, user3_.modified_at as modifie11_24_3_, user3_.national_code as nationa12_24_3_, user3_.password as passwor13_24_3_, user3_.personnel_id as personn14_24_3_, user3_.phone as phone15_24_3_, user3_.sso_validation as sso_val16_24_3_, user3_.telephone as telepho17_24_3_, user3_.version as version18_24_3_ from employees employee0_ left outer join companies company1_ on employee0_.company_id=company1_.id left outer join companies company2_ on company1_.parent_id=company2_.id left outer join users user3_ on employee0_.user_id=user3_.id where employee0_.id=?
Hibernate: select employee0_.id as id1_7_0_, employee0_.company_id as company_9_7_0_, employee0_.created_at as created_2_7_0_, employee0_.isargari_type as isargari3_7_0_, employee0_.modified_at as modified4_7_0_, employee0_.personnel_id as personne5_7_0_, employee0_.roles as roles6_7_0_, employee0_.status as status7_7_0_, employee0_.type as type8_7_0_, employee0_.user_id as user_id10_7_0_, company1_.id as id1_2_1_, company1_.areas as areas2_2_1_, company1_.company_code as company_3_2_1_, company1_.created_at as created_4_2_1_, company1_.direction as directio5_2_1_, company1_.financial_code as financia6_2_1_, company1_.modified_at as modified7_2_1_, company1_.name as name8_2_1_, company1_.parent_id as parent_11_2_1_, company1_.province as province9_2_1_, company1_.zone as zone10_2_1_, company2_.id as id1_2_2_, company2_.areas as areas2_2_2_, company2_.company_code as company_3_2_2_, company2_.created_at as created_4_2_2_, company2_.direction as directio5_2_2_, company2_.financial_code as financia6_2_2_, company2_.modified_at as modified7_2_2_, company2_.name as name8_2_2_, company2_.parent_id as parent_11_2_2_, company2_.province as province9_2_2_, company2_.zone as zone10_2_2_, user3_.id as id1_24_3_, user3_.birth_date as birth_da2_24_3_, user3_.created_at as created_3_24_3_, user3_.email as email4_24_3_, user3_.father_name as father_n5_24_3_, user3_.first_name as first_na6_24_3_, user3_.gender as gender7_24_3_, user3_.isargari_type as isargari8_24_3_, user3_.last_name as last_nam9_24_3_, user3_.marital_state as marital10_24_3_, user3_.modified_at as modifie11_24_3_, user3_.national_code as nationa12_24_3_, user3_.password as passwor13_24_3_, user3_.personnel_id as personn14_24_3_, user3_.phone as phone15_24_3_, user3_.sso_validation as sso_val16_24_3_, user3_.telephone as telepho17_24_3_, user3_.version as version18_24_3_ from employees employee0_ left outer join companies company1_ on employee0_.company_id=company1_.id left outer join companies company2_ on company1_.parent_id=company2_.id left outer join users user3_ on employee0_.user_id=user3_.id where employee0_.id=?
Hibernate: select employee0_.id as id1_7_0_, employee0_.company_id as company_9_7_0_, employee0_.created_at as created_2_7_0_, employee0_.isargari_type as isargari3_7_0_, employee0_.modified_at as modified4_7_0_, employee0_.personnel_id as personne5_7_0_, employee0_.roles as roles6_7_0_, employee0_.status as status7_7_0_, employee0_.type as type8_7_0_, employee0_.user_id as user_id10_7_0_, company1_.id as id1_2_1_, company1_.areas as areas2_2_1_, company1_.company_code as company_3_2_1_, company1_.created_at as created_4_2_1_, company1_.direction as directio5_2_1_, company1_.financial_code as financia6_2_1_, company1_.modified_at as modified7_2_1_, company1_.name as name8_2_1_, company1_.parent_id as parent_11_2_1_, company1_.province as province9_2_1_, company1_.zone as zone10_2_1_, company2_.id as id1_2_2_, company2_.areas as areas2_2_2_, company2_.company_code as company_3_2_2_, company2_.created_at as created_4_2_2_, company2_.direction as directio5_2_2_, company2_.financial_code as financia6_2_2_, company2_.modified_at as modified7_2_2_, company2_.name as name8_2_2_, company2_.parent_id as parent_11_2_2_, company2_.province as province9_2_2_, company2_.zone as zone10_2_2_, user3_.id as id1_24_3_, user3_.birth_date as birth_da2_24_3_, user3_.created_at as created_3_24_3_, user3_.email as email4_24_3_, user3_.father_name as father_n5_24_3_, user3_.first_name as first_na6_24_3_, user3_.gender as gender7_24_3_, user3_.isargari_type as isargari8_24_3_, user3_.last_name as last_nam9_24_3_, user3_.marital_state as marital10_24_3_, user3_.modified_at as modifie11_24_3_, user3_.national_code as nationa12_24_3_, user3_.password as passwor13_24_3_, user3_.personnel_id as personn14_24_3_, user3_.phone as phone15_24_3_, user3_.sso_validation as sso_val16_24_3_, user3_.telephone as telepho17_24_3_, user3_.version as version18_24_3_ from employees employee0_ left outer join companies company1_ on employee0_.company_id=company1_.id left outer join companies company2_ on company1_.parent_id=company2_.id left outer join users user3_ on employee0_.user_id=user3_.id where employee0_.id=?
Hibernate: select employee0_.id as id1_7_0_, employee0_.company_id as company_9_7_0_, employee0_.created_at as created_2_7_0_, employee0_.isargari_type as isargari3_7_0_, employee0_.modified_at as modified4_7_0_, employee0_.personnel_id as personne5_7_0_, employee0_.roles as roles6_7_0_, employee0_.status as status7_7_0_, employee0_.type as type8_7_0_, employee0_.user_id as user_id10_7_0_, company1_.id as id1_2_1_, company1_.areas as areas2_2_1_, company1_.company_code as company_3_2_1_, company1_.created_at as created_4_2_1_, company1_.direction as directio5_2_1_, company1_.financial_code as financia6_2_1_, company1_.modified_at as modified7_2_1_, company1_.name as name8_2_1_, company1_.parent_id as parent_11_2_1_, company1_.province as province9_2_1_, company1_.zone as zone10_2_1_, company2_.id as id1_2_2_, company2_.areas as areas2_2_2_, company2_.company_code as company_3_2_2_, company2_.created_at as created_4_2_2_, company2_.direction as directio5_2_2_, company2_.financial_code as financia6_2_2_, company2_.modified_at as modified7_2_2_, company2_.name as name8_2_2_, company2_.parent_id as parent_11_2_2_, company2_.province as province9_2_2_, company2_.zone as zone10_2_2_, user3_.id as id1_24_3_, user3_.birth_date as birth_da2_24_3_, user3_.created_at as created_3_24_3_, user3_.email as email4_24_3_, user3_.father_name as father_n5_24_3_, user3_.first_name as first_na6_24_3_, user3_.gender as gender7_24_3_, user3_.isargari_type as isargari8_24_3_, user3_.last_name as last_nam9_24_3_, user3_.marital_state as marital10_24_3_, user3_.modified_at as modifie11_24_3_, user3_.national_code as nationa12_24_3_, user3_.password as passwor13_24_3_, user3_.personnel_id as personn14_24_3_, user3_.phone as phone15_24_3_, user3_.sso_validation as sso_val16_24_3_, user3_.telephone as telepho17_24_3_, user3_.version as version18_24_3_ from employees employee0_ left outer join companies company1_ on employee0_.company_id=company1_.id left outer join companies company2_ on company1_.parent_id=company2_.id left outer join users user3_ on employee0_.user_id=user3_.id where employee0_.id=?
Hibernate: select employee0_.id as id1_7_0_, employee0_.company_id as company_9_7_0_, employee0_.created_at as created_2_7_0_, employee0_.isargari_type as isargari3_7_0_, employee0_.modified_at as modified4_7_0_, employee0_.personnel_id as personne5_7_0_, employee0_.roles as roles6_7_0_, employee0_.status as status7_7_0_, employee0_.type as type8_7_0_, employee0_.user_id as user_id10_7_0_, company1_.id as id1_2_1_, company1_.areas as areas2_2_1_, company1_.company_code as company_3_2_1_, company1_.created_at as created_4_2_1_, company1_.direction as directio5_2_1_, company1_.financial_code as financia6_2_1_, company1_.modified_at as modified7_2_1_, company1_.name as name8_2_1_, company1_.parent_id as parent_11_2_1_, company1_.province as province9_2_1_, company1_.zone as zone10_2_1_, company2_.id as id1_2_2_, company2_.areas as areas2_2_2_, company2_.company_code as company_3_2_2_, company2_.created_at as created_4_2_2_, company2_.direction as directio5_2_2_, company2_.financial_code as financia6_2_2_, company2_.modified_at as modified7_2_2_, company2_.name as name8_2_2_, company2_.parent_id as parent_11_2_2_, company2_.province as province9_2_2_, company2_.zone as zone10_2_2_, user3_.id as id1_24_3_, user3_.birth_date as birth_da2_24_3_, user3_.created_at as created_3_24_3_, user3_.email as email4_24_3_, user3_.father_name as father_n5_24_3_, user3_.first_name as first_na6_24_3_, user3_.gender as gender7_24_3_, user3_.isargari_type as isargari8_24_3_, user3_.last_name as last_nam9_24_3_, user3_.marital_state as marital10_24_3_, user3_.modified_at as modifie11_24_3_, user3_.national_code as nationa12_24_3_, user3_.password as passwor13_24_3_, user3_.personnel_id as personn14_24_3_, user3_.phone as phone15_24_3_, user3_.sso_validation as sso_val16_24_3_, user3_.telephone as telepho17_24_3_, user3_.version as version18_24_3_ from employees employee0_ left outer join companies company1_ on employee0_.company_id=company1_.id left outer join companies company2_ on company1_.parent_id=company2_.id left outer join users user3_ on employee0_.user_id=user3_.id where employee0_.id=?
Hibernate: select employee0_.id as id1_7_0_, employee0_.company_id as company_9_7_0_, employee0_.created_at as created_2_7_0_, employee0_.isargari_type as isargari3_7_0_, employee0_.modified_at as modified4_7_0_, employee0_.personnel_id as personne5_7_0_, employee0_.roles as roles6_7_0_, employee0_.status as status7_7_0_, employee0_.type as type8_7_0_, employee0_.user_id as user_id10_7_0_, company1_.id as id1_2_1_, company1_.areas as areas2_2_1_, company1_.company_code as company_3_2_1_, company1_.created_at as created_4_2_1_, company1_.direction as directio5_2_1_, company1_.financial_code as financia6_2_1_, company1_.modified_at as modified7_2_1_, company1_.name as name8_2_1_, company1_.parent_id as parent_11_2_1_, company1_.province as province9_2_1_, company1_.zone as zone10_2_1_, company2_.id as id1_2_2_, company2_.areas as areas2_2_2_, company2_.company_code as company_3_2_2_, company2_.created_at as created_4_2_2_, company2_.direction as directio5_2_2_, company2_.financial_code as financia6_2_2_, company2_.modified_at as modified7_2_2_, company2_.name as name8_2_2_, company2_.parent_id as parent_11_2_2_, company2_.province as province9_2_2_, company2_.zone as zone10_2_2_, user3_.id as id1_24_3_, user3_.birth_date as birth_da2_24_3_, user3_.created_at as created_3_24_3_, user3_.email as email4_24_3_, user3_.father_name as father_n5_24_3_, user3_.first_name as first_na6_24_3_, user3_.gender as gender7_24_3_, user3_.isargari_type as isargari8_24_3_, user3_.last_name as last_nam9_24_3_, user3_.marital_state as marital10_24_3_, user3_.modified_at as modifie11_24_3_, user3_.national_code as nationa12_24_3_, user3_.password as passwor13_24_3_, user3_.personnel_id as personn14_24_3_, user3_.phone as phone15_24_3_, user3_.sso_validation as sso_val16_24_3_, user3_.telephone as telepho17_24_3_, user3_.version as version18_24_3_ from employees employee0_ left outer join companies company1_ on employee0_.company_id=company1_.id left outer join companies company2_ on company1_.parent_id=company2_.id left outer join users user3_ on employee0_.user_id=user3_.id where employee0_.id=?
Hibernate: select employee0_.id as id1_7_0_, employee0_.company_id as company_9_7_0_, employee0_.created_at as created_2_7_0_, employee0_.isargari_type as isargari3_7_0_, employee0_.modified_at as modified4_7_0_, employee0_.personnel_id as personne5_7_0_, employee0_.roles as roles6_7_0_, employee0_.status as status7_7_0_, employee0_.type as type8_7_0_, employee0_.user_id as user_id10_7_0_, company1_.id as id1_2_1_, company1_.areas as areas2_2_1_, company1_.company_code as company_3_2_1_, company1_.created_at as created_4_2_1_, company1_.direction as directio5_2_1_, company1_.financial_code as financia6_2_1_, company1_.modified_at as modified7_2_1_, company1_.name as name8_2_1_, company1_.parent_id as parent_11_2_1_, company1_.province as province9_2_1_, company1_.zone as zone10_2_1_, company2_.id as id1_2_2_, company2_.areas as areas2_2_2_, company2_.company_code as company_3_2_2_, company2_.created_at as created_4_2_2_, company2_.direction as directio5_2_2_, company2_.financial_code as financia6_2_2_, company2_.modified_at as modified7_2_2_, company2_.name as name8_2_2_, company2_.parent_id as parent_11_2_2_, company2_.province as province9_2_2_, company2_.zone as zone10_2_2_, user3_.id as id1_24_3_, user3_.birth_date as birth_da2_24_3_, user3_.created_at as created_3_24_3_, user3_.email as email4_24_3_, user3_.father_name as father_n5_24_3_, user3_.first_name as first_na6_24_3_, user3_.gender as gender7_24_3_, user3_.isargari_type as isargari8_24_3_, user3_.last_name as last_nam9_24_3_, user3_.marital_state as marital10_24_3_, user3_.modified_at as modifie11_24_3_, user3_.national_code as nationa12_24_3_, user3_.password as passwor13_24_3_, user3_.personnel_id as personn14_24_3_, user3_.phone as phone15_24_3_, user3_.sso_validation as sso_val16_24_3_, user3_.telephone as telepho17_24_3_, user3_.version as version18_24_3_ from employees employee0_ left outer join companies company1_ on employee0_.company_id=company1_.id left outer join companies company2_ on company1_.parent_id=company2_.id left outer join users user3_ on employee0_.user_id=user3_.id where employee0_.id=?
Hibernate: select employee0_.id as id1_7_0_, employee0_.company_id as company_9_7_0_, employee0_.created_at as created_2_7_0_, employee0_.isargari_type as isargari3_7_0_, employee0_.modified_at as modified4_7_0_, employee0_.personnel_id as personne5_7_0_, employee0_.roles as roles6_7_0_, employee0_.status as status7_7_0_, employee0_.type as type8_7_0_, employee0_.user_id as user_id10_7_0_, company1_.id as id1_2_1_, company1_.areas as areas2_2_1_, company1_.company_code as company_3_2_1_, company1_.created_at as created_4_2_1_, company1_.direction as directio5_2_1_, company1_.financial_code as financia6_2_1_, company1_.modified_at as modified7_2_1_, company1_.name as name8_2_1_, company1_.parent_id as parent_11_2_1_, company1_.province as province9_2_1_, company1_.zone as zone10_2_1_, company2_.id as id1_2_2_, company2_.areas as areas2_2_2_, company2_.company_code as company_3_2_2_, company2_.created_at as created_4_2_2_, company2_.direction as directio5_2_2_, company2_.financial_code as financia6_2_2_, company2_.modified_at as modified7_2_2_, company2_.name as name8_2_2_, company2_.parent_id as parent_11_2_2_, company2_.province as province9_2_2_, company2_.zone as zone10_2_2_, user3_.id as id1_24_3_, user3_.birth_date as birth_da2_24_3_, user3_.created_at as created_3_24_3_, user3_.email as email4_24_3_, user3_.father_name as father_n5_24_3_, user3_.first_name as first_na6_24_3_, user3_.gender as gender7_24_3_, user3_.isargari_type as isargari8_24_3_, user3_.last_name as last_nam9_24_3_, user3_.marital_state as marital10_24_3_, user3_.modified_at as modifie11_24_3_, user3_.national_code as nationa12_24_3_, user3_.password as passwor13_24_3_, user3_.personnel_id as personn14_24_3_, user3_.phone as phone15_24_3_, user3_.sso_validation as sso_val16_24_3_, user3_.telephone as telepho17_24_3_, user3_.version as version18_24_3_ from employees employee0_ left outer join companies company1_ on employee0_.company_id=company1_.id left outer join companies company2_ on company1_.parent_id=company2_.id left outer join users user3_ on employee0_.user_id=user3_.id where employee0_.id=?
Hibernate: select maincontra0_.id as id1_10_, maincontra0_.action_date as action_d2_10_, maincontra0_.base as base3_10_, maincontra0_.created_at as created_4_10_, maincontra0_.employee_id as employee7_10_, maincontra0_.expiration_date as expirati5_10_, maincontra0_.modified_at as modified6_10_, maincontra0_.process_id as process_8_10_ from main_contracts maincontra0_

答案1

得分: 1

你不需要显式保存实体,如果该实体在一级缓存中。

我怀疑你改变了 Process 的某些属性,当你调用 amazingRepo.findAll() 时,它会导致对 Amazing 进行刷新,以及所有依赖它的实体(包括 Process)。

英文:

You don't need explicitly save entity if said entity in first level cache.

I suspect you change some attribute of Process, when you call amazingRepo.findAll() it cause flush of Amazing and all entities it depend on (which includes Process).

答案2

得分: 1

不同类型的LockModeType存在一个要点,它们并不都会在更新时增加版本:
> OPTIMISTIC – 它为包含版本属性的所有实体获取乐观读取锁

> OPTIMISTIC_FORCE_INCREMENT – 它获得与 OPTIMISTIC 相同的乐观锁,并且额外增加版本属性值

> READ – 它是 OPTIMISTIC 的同义词

> WRITE – 它是 OPTIMISTIC_FORCE_INCREMENT 的同义词

一个小示例配置的方式:

@Lock(LockModeType.OPTIMISTIC)
public Optional&lt;YourEntity&gt; findById(Long id);

要了解更多关于此主题的信息,您还可以查阅以下链接(我从第一个链接中引用):

英文:

There is a point in different types of LockModeType, not all of them increment the version on update:
> OPTIMISTIC – it obtains an optimistic read lock for all entities containing a version attribute

> OPTIMISTIC_FORCE_INCREMENT – it obtains an optimistic lock the same as OPTIMISTIC and additionally increments the version attribute value

> READ – it's a synonym for OPTIMISTIC

> WRITE – it's a synonym for OPTIMISTIC_FORCE_INCREMENT

A small example of how to config:

@Lock(LockModeType.OPTIMISTIC)
public Optional&lt;YourEntity&gt; findById(Long id);

to know more about the topic, you can check also these links (I've quoted from the first one):

huangapple
  • 本文由 发表于 2020年9月9日 15:28:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/63806688.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定