I have an entity with an ElementCollection
{code:java} @Entity @Table(name = "TEST_EC_PERSON") public class Person { @Id @GeneratedValue private long id;
@Version private long version;
@Column(name = "NAME", length = 100) private String name;
@ElementCollection(fetch = FetchType.EAGER) @CollectionTable(name = "TEST_EC_ADDRESS", joinColumns=@JoinColumn(name="person_id")) private Set<Address> addresses = new HashSet<Address>(); {code}
When I read the entity within a Transaction the members of the ElementCollection are deleted and reinserted on commit. This increments the version of the entity. I do not change Entity and Embeddables.
When I read the entity without Transaction the version is not incremented.
{code} 23:06:51,279 DEBUG SQL:92 - select addresses0_.person_id as person_i1_0_0_, addresses0_.city as city2_0_0_, addresses0_.street as street3_0_0_ from TEST_EC_ADDRESS addresses0_ where addresses0_.person_id=? 23:06:51,280 TRACE BasicBinder:65 - binding parameter [1] as [BIGINT] - [1] 23:06:51,280 TRACE BasicExtractor:61 - extracted value ([person_i1_0_0_] : [BIGINT]) - [1] 23:06:51,281 TRACE BasicExtractor:61 - extracted value ([city2_0_0_] : [VARCHAR]) - [City 2] 23:06:51,281 TRACE BasicExtractor:61 - extracted value ([street3_0_0_] : [VARCHAR]) - [Street 2] 23:06:51,281 TRACE BasicExtractor:61 - extracted value ([person_i1_0_0_] : [BIGINT]) - [1] 23:06:51,281 TRACE BasicExtractor:61 - extracted value ([city2_0_0_] : [VARCHAR]) - [City 1] 23:06:51,282 TRACE BasicExtractor:61 - extracted value ([street3_0_0_] : [VARCHAR]) - [Street 1] 23:06:51,282 DEBUG SQL:92 - update TEST_EC_PERSON set NAME=?, version=? where id=? and version=? 23:06:51,283 TRACE BasicBinder:65 - binding parameter [1] as [VARCHAR] - [Person 1] 23:06:51,283 TRACE BasicBinder:65 - binding parameter [2] as [BIGINT] - [2] 23:06:51,283 TRACE BasicBinder:65 - binding parameter [3] as [BIGINT] - [1] 23:06:51,284 TRACE BasicBinder:65 - binding parameter [4] as [BIGINT] - [1] 23:06:51,285 DEBUG SQL:92 - delete from TEST_EC_ADDRESS where person_id=? 23:06:51,286 TRACE BasicBinder:65 - binding parameter [1] as [BIGINT] - [1] 23:06:51,287 DEBUG SQL:92 - insert into TEST_EC_ADDRESS (person_id, city, street) values (?, ?, ?) 23:06:51,287 TRACE BasicBinder:65 - binding parameter [1] as [BIGINT] - [1] 23:06:51,287 TRACE BasicBinder:65 - binding parameter [2] as [VARCHAR] - [City 2] 23:06:51,287 TRACE BasicBinder:65 - binding parameter [3] as [VARCHAR] - [Street 2] 23:06:51,289 DEBUG SQL:92 - insert into TEST_EC_ADDRESS (person_id, city, street) values (?, ?, ?) 23:06:51,289 TRACE BasicBinder:65 - binding parameter [1] as [BIGINT] - [1] 23:06:51,289 TRACE BasicBinder:65 - binding parameter [2] as [VARCHAR] - [City 1] 23:06:51,289 TRACE BasicBinder:65 - binding parameter [3] as [VARCHAR] - [Street 1] {code} |
|