gpt4 book ai didi

Spring Boot Data Rest POST 返回 204 但只有 SELECTS

转载 作者:行者123 更新时间:2023-12-04 15:32:26 25 4
gpt4 key购买 nike

所以在我切换到 Boot 之前这是有效的。基本上我能够将文本/uri-list 发布到@OneToMany 资源就好了。我将我的项目切换为使用 Boot 并在此过程中的某个地方停止工作。我可以在@ManyToOne 端放置一个文本/uri 列表,但这不是我想要做的。

当我提交 POST 时,我得到 204 响应,但我只能在控制台上看到 SQL 选择而不插入任何内容。
编辑:我使用 Postman,但这是一个执行/返回相同的 curl 命令

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

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=?

这是我的相关类(class):
@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;

另一个:
@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;

如果我遗漏了任何其他相关信息,请告诉我,我会提供。

最佳答案

如果你想保持双向,你似乎有两个选择:

  • 删除 mappedBy = "developer"并且让JPA使用joinable来管理一对多的关系。

  • 开发商:
    @OneToMany(cascade = CascadeType.ALL)
    @JoinTable(
    name="DeveloperGame",
    joinColumns = @JoinColumn( name="dev_id"),
    inverseJoinColumns = @JoinColumn( name="game_id")
    )
    private List<Game> gameList;

    游戏:
    @ManyToOne
    @JoinTable(
    name="DeveloperGame",
    joinColumns = @JoinColumn( name="game_id"),
    inverseJoinColumns = @JoinColumn( name="dev_id")
    )
    private Developer developer;
  • 删除 mappedBy = "developer"并添加一个 @JoinColumn如果你不想使用joinable(让你在关系的两边都有一个joincolumn,列名相同

  • 开发商:
    @OneToMany(cascade = CascadeType.ALL)
    @JoinColumn(name = "devId")
    private List<Game> gameList;

    游戏:
    @ManyToOne
    @JoinColumn(name = "devId")
    private Developer developer;

    我确实想知道这是设计使然还是 Spring Data REST 中的错误。

    关于Spring Boot Data Rest POST 返回 204 但只有 SELECTS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35910850/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com