How to save manytomany according to order of the List in Spring Data Jpa

Zevin Chen

There're my model code

@Entity
@Table(name = "jade")
public class Jade extends BaseEntity implements Serializable {

    @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @JoinTable(name = "jade_feature", 
     joinColumns = { @JoinColumn(name = "jade_id", referencedColumnName = "id") }, 
     inverseJoinColumns = { @JoinColumn(name = "feature_id", referencedColumnName = "id") })
    private List<Feature> features;

}

When I save the model, the data of List weren't saved according to the List's add method.

For example:

List<Feature> features = new ArrayList<Feature>();
features.add(a);
features.add(b);
features.add(c);
Jade jade = new Jade(features);
jade.saveAndFlush();

But the database data were 【c, a, b】Like this inserted. How to deal with this problem?

shankarsh15

You have to make use of @OrderColumn to maintain order of the List collection .

Please have a look at the docs below:

http://docs.oracle.com/javaee/6/api/javax/persistence/OrderColumn.html

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Spring Data JPA: query ManyToMany

From Dev

Spring data jpa save

From Dev

Spring data jpa save

From Dev

JPA : How to save list with order in a many-to-many relationship

From Java

Query method in Spring Data JPA for relation @ManyToMany

From Dev

Spring Data JPA Specification for a ManyToMany Unidirectional Relationship

From Dev

How to save and load ordered data using Spring Data JPA?

From Dev

Spring Data JPA: query ManyToMany, How Can I get the data from mapped Class?

From Dev

How to save entities with manually assigned identifiers using Spring Data JPA?

From Dev

How to keep order provided in "in" clause in Spring Data JPA or Hibernate

From Dev

Spring JPA fetch ManyToMany

From Dev

Spring JPA fetch ManyToMany

From Dev

How to order list according to array values in python?

From Dev

How to order list according to array values in python?

From Dev

Generation query when the ManyToMany relationship is used by Spring Data Jpa project

From Dev

Spring Data Jpa - ManyToMany - delete entities of the join table

From Dev

Avoid multiple delete statements with Spring Data JPA on ManyToMany

From Dev

SPRING DATA JPA save @OneToMany relation

From Dev

Spring Data JPA Many to Many save to set

From Dev

Spring Data Jpa Save Test Fails

From Dev

Secondary save method in a Spring Data JPA repo?

From Dev

Save entities in Spring Data JPA which contains a list of another entity type

From Dev

Order By Date Desc Limit in Spring Data JPA

From Dev

Spring JPA how to persist parent when the child is persisted in ManyToMany relationship

From Java

How can I implement a Save Or Update function using Spring Data Jpa?

From Dev

how to select data frame according to index NOT in a list

From Dev

how to select data frame according to index NOT in a list

From Dev

How to sort data in spring jpa?

From Dev

Unable to setup @ManyToMany and @OneToOne relationship correctly for bi directional Spring Data JPA and Spring REST

Related Related

  1. 1

    Spring Data JPA: query ManyToMany

  2. 2

    Spring data jpa save

  3. 3

    Spring data jpa save

  4. 4

    JPA : How to save list with order in a many-to-many relationship

  5. 5

    Query method in Spring Data JPA for relation @ManyToMany

  6. 6

    Spring Data JPA Specification for a ManyToMany Unidirectional Relationship

  7. 7

    How to save and load ordered data using Spring Data JPA?

  8. 8

    Spring Data JPA: query ManyToMany, How Can I get the data from mapped Class?

  9. 9

    How to save entities with manually assigned identifiers using Spring Data JPA?

  10. 10

    How to keep order provided in "in" clause in Spring Data JPA or Hibernate

  11. 11

    Spring JPA fetch ManyToMany

  12. 12

    Spring JPA fetch ManyToMany

  13. 13

    How to order list according to array values in python?

  14. 14

    How to order list according to array values in python?

  15. 15

    Generation query when the ManyToMany relationship is used by Spring Data Jpa project

  16. 16

    Spring Data Jpa - ManyToMany - delete entities of the join table

  17. 17

    Avoid multiple delete statements with Spring Data JPA on ManyToMany

  18. 18

    SPRING DATA JPA save @OneToMany relation

  19. 19

    Spring Data JPA Many to Many save to set

  20. 20

    Spring Data Jpa Save Test Fails

  21. 21

    Secondary save method in a Spring Data JPA repo?

  22. 22

    Save entities in Spring Data JPA which contains a list of another entity type

  23. 23

    Order By Date Desc Limit in Spring Data JPA

  24. 24

    Spring JPA how to persist parent when the child is persisted in ManyToMany relationship

  25. 25

    How can I implement a Save Or Update function using Spring Data Jpa?

  26. 26

    how to select data frame according to index NOT in a list

  27. 27

    how to select data frame according to index NOT in a list

  28. 28

    How to sort data in spring jpa?

  29. 29

    Unable to setup @ManyToMany and @OneToOne relationship correctly for bi directional Spring Data JPA and Spring REST

HotTag

Archive