cuba-platform / cuba

CUBA Platform is a high level framework for enterprise applications development
https://www.cuba-platform.com
Apache License 2.0
1.34k stars 219 forks source link

Incorrect loading of entity with a list attribute when entity cache is enabled #3187

Closed pasha9819 closed 3 years ago

pasha9819 commented 3 years ago

Environment

Description of the bug

Minimal reproducible example:

@Table(name = "LISTANDCACHE_LEAF") @Entity(name = "listandcache_Leaf") @NamePattern("%s|description") public class Leaf extends StandardEntity {

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "TREE_ID")
private Tree tree;

@Column(name = "DESCRIPTION")
private String description;

// get, set

}

- enable entity cache

eclipselink.cache.shared.listandcache_Tree = true eclipselink.cache.shared.listandcache_Leaf = true


- create Tree entity with one composite Leaf entity
- save Tree entity
- try to open Tree Editor screen

#### Expected behavior
- Tree Editor screen will be open  
#### Actual behavior
- `IllegalStateException: Changed instance com.company.listandcache.entity.Tree-cac725da-31da-9edc-fdd1-d9a560393623 [managed,detached] in read-only transaction`

This exception occurs in `com.haulmont.cuba.core.sys.persistence.PersistenceImplSupport$ContainerResourceSynchronization.beforeCommit(PersistenceImplSupport.java:423) ~[cuba-core-7.2.10.jar:7.2.10]` occurs due to changes in the `leafs` attribute of the Tree entity, but there were no explicit changes to this attribute after saving to the database
pasha9819 commented 3 years ago

https://user-images.githubusercontent.com/29690565/117969894-0e56a800-b339-11eb-9754-fc791fa108f9.mp4

plakhov commented 3 years ago

Fixed in #3166