|
I'm using the IndexedCollections that have recently been fixed. I seem to be getting random situations where the ordercolumn gets a wrong number assigned and I seem to be having retrieval issues at times.
I have not been able to write a test case that reproduces the issue yet although I do seem to get this frequently in our website.
The basic scenario is this:
-
There is a course
-
You add a module to the course. You then get automatically redirected to another page to add assets to the module based on the id of the just saved module
-
This page sometimes generates an ObjectNotFoundException exception when we try to retrieve the just created module by the past id
-
A reload will load the module correctly, even though the index may still be offset incorrectly
So, there are two problems here: 1. Sometimes a module that has just been saved is not retrievable 2. Sometimes the indexcolumn is not properly updated. For instance on a course with 7 modules, adding a new one suddenly generated an indexcolumn value of 4
The two seem to be related I can't yet say if they occur together 100%. Number 1 suggests a transactional issue but the save happens in a regular transactional context (Spring managed + opensessioninview) and the issue appears across two pages.
@Entity
@DiscriminatorValue(value = "CRS")
@Indexed
public class Course extends Group<CourseMember> {
private List<Module> modules = new ArrayList<Module>();
@OneToMany(cascade=CascadeType.ALL,fetch=FetchType.LAZY, mappedBy="course",orphanRemoval=true)
@OrderColumn
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE,region=CacheRegion.COURSE)
public List<Module> getModules() {
return modules;
}
[...]
}
@Entity
@Table
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE,region=CacheRegion.COURSE)
public class Module implements Serializable{
private Long id;
private Course course;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(updatable = false, insertable = false)
public Long getId() {
return id;
}
@ManyToOne(fetch=FetchType.LAZY,optional=false)
@JoinColumn(nullable=false, insertable= true, updatable=false)
@NotNull
public Course getCourse() {
return course;
}
[...]
}
I save the module like this
boolean nw = module.getId() == null;
module = (Module) dao.saveObject(module);
if(nw){
Course course = module.getCourse();
course.getModules().add(module);
dao.save(course);
}
return module;
|