Code:
@Entity
@Audited
public class Template {
@Id
Long id;
@ManyToMany(cascade = CascadeType.ALL)
@JoinTable(name = "template_section")
List<Section> sections;
...
}
@Entity
@Audited
public class Section {
@Id
Long id;
...
}
Steps Taken
-----
1) Create a few sections Section A (
rev 1)
Section B (
rev 2)
Section C (
rev 3)
2) Create a template with these sections Template A (
rev 4)
Section A, Section B, SectionC (
join table rev 4)
3) Update the section and remove a section Template A (
rev 5)
Section A, Section B (
join table rev 5)
When I load
revision 5 of the template I would expect a template with only two sections, instead it returns a template with all three. I think the key is in the generate SQL which specifies a revision <=
5.
The template_sections_aud join table contains
Code:
REV STATEMENT SECTIONS REVTYPE
------------------------------------------
5 1 1 0
5 1 2 0
4 1 1 0
4 1 2 0
4 1 3 0
The generated SQL query to pull back the sections returns (column names changed to improve readability):
Code:
TEMPLATE_SECTION_REV TEMPLATE_ID TEMPLATE_SECTION_ID SECTION_ID SECTION_REV
---------------------------------------------------------------------------------------
5 1 1 1 1 <- Section A
5 1 2 2 2 <- Section B
4 1 3 3 3 <- Section C (Shouldn't be here)
Have I setup my relationship incorrectly? Why does the revisioned entity have all three sections?