Spring Data - persisting two lists in a domain object

Viewed 50

I have an issue with a particular use case I am trying to implement. The reactjs client passes two lists (from two tables) that use the same data.

@Entity(name = "SCOPE_STAGE")
@Slf4j
@Getter
@Setter

public class ScopeStage extends {

      ....

      private List<ScopeSelection> inScopeSelection    = new ArrayList<>();
      private List<ScopeSelection> outOfScopeSelection = new ArrayList<>();

      ...
}

With this, I get a Bag exception because of the cartesian join that is being performed with the query. I know one common solution is to switch to a Set, but the ordering in which they are inserted and later changed on the UI needs to be preserved.

Ideally, I want to stick to standard Spring Data/JPA and not introduce implementation specific code. I have some options such as adding an order column to the table and then I could use a set and the client/server could order based on that column.

I've looked through this on Google and a lot of the solutions seem quite old & messy for what seems on the surface to be a rather trivial thing to achieve.

Can anyone advise on the best approach to tackle this?

0 Answers
Related