spring-projects / spring-data-rest

Simplifies building hypermedia-driven REST web services on top of Spring Data repositories
https://spring.io/projects/spring-data-rest
Apache License 2.0
909 stars 558 forks source link

POST text/uri-list to collection does not add association [DATAREST-784] #1157

Open spring-projects-issues opened 8 years ago

spring-projects-issues commented 8 years ago

Jose Montoya opened DATAREST-784 and commented

When I submit the POST a text/uri-list to a @OneToMany I get a 204 response, but I can see the SQL on my console only Selecting and not inserting anything. EDIT: I use Postman, but here's the curl command that does/returns the same

curl -v -X POST -H "Content-Type: text/uri-list" -d "http://localhost:8080/games/2" http://localhost:8080/developers/1/gameList

And the logger on IDEA:

Hibernate: select developer0_.developer_id as develope1_1_0_, developer0_.name as name2_1_0_ from developer developer0_ where developer0_.developer_id=?
Hibernate: select game0_.game_id as game_id1_6_0_, game0_.developer_id as develope5_6_0_, game0_.esrb_rating as esrb_rat2_6_0_, game0_.name as name3_6_0_, game0_.release_date as release_4_6_0_, developer1_.developer_id as develope1_1_1_, developer1_.name as name2_1_1_ from game game0_ left outer join developer developer1_ on game0_.developer_id=developer1_.developer_id where game0_.game_id=?

Here are my relevant classes:

@Entity
public class Developer {
    @Id
    @GeneratedValue
    @Column(name = "developerId")
    private Long id;

    private String name;

    @OneToMany(mappedBy = "developer", cascade = CascadeType.ALL)
    private List<Game> gameList;

Other one:

@Entity
public class Game {
    @Id
    @GeneratedValue
    @Column(name = "gameId")
    private Long id;

    private String name;

    private Date releaseDate;

    private ESRBRating esrbRating;

    @ManyToMany(mappedBy = "gameList", cascade = CascadeType.ALL)
    private List<User> userList;

    @ManyToOne
    @JoinColumn(name = "developerId")
    private Developer developer;

If I misunderstood the docs, or I'm doing something wrong, or this is a known issue (couldn't find any) please let me know


Affects: 2.5 M1 (Hopper)

Reference URL: http://stackoverflow.com/questions/35910850/spring-boot-data-rest-post-returns-204-but-only-selects/35926199

1 votes, 4 watchers

spring-projects-issues commented 8 years ago

Jose Montoya commented

Might be related to https://jira.spring.io/browse/DATAREST-771 as making the relation unidirectional allows the insert to happen, but I need it to be bidirectional

spring-projects-issues commented 7 years ago

Davy De Waele commented

If you want to keep it bidirectional I think you have 2 options :

I do wonder if this is by design or if this is a bug in Spring Data REST