I have the following model:
many to many between entity Foo
and Bar
. Foo has a LinkedHashSet of Bar
annotated with @OrderBy
.
Controller includes a method that first saves a new Bar to the set, and then gets all Bar from one Foo.
Set<Bar> methodName(FooId fid, Bar b){
fooService.addBar(fid, b);
return fooService.getBarsOfFoo(fid);
}
service methods:
@Transactional
void addBar(UUID fid, Bar b){
Foo f = fooRepository.getFoo(fid);
f.getBars().add(b);
}
@Transactional(readOnly = true)
Set<Bar> getBarsOfFoo(UUID fid){
return fooRepository.getFoo(fid).getBars();
}
the issue is that when calling the method, all Bars are ordered except the last introduced one. I think it has something to do with hibernate first-level caching, but I am not sure when the session associated with that method starts or ends.
Are both session methods from that controller method run within the same session?