所以在我切换到Boot之前这个工作正常.基本上我能够将text / uri-list发布到@OneToMany资源就好了.我将项目切换为使用Boot,并在此过程中停止工作.我可以在@ManyToOne结尾处输入text / uri-list,但这不是我想要做的.
当我提交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=?
这是我的相关课程:
@Entity
public class Developer {
@Id
@GeneratedValue
@Column(name = "developerId")
private Long id;
private String name;
@OneToMany(mappedBy = "developer",cascade = CascadeType.ALL)
private List
另外一个:
@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
如果我遗漏任何其他相关信息,请告诉我,我会提供.
最佳答案
如果你想保持双向,你似乎有两个选择:
原文链接:https://www.f2er.com/spring/432456.html>删除mappedBy =“developer”并让JPA使用连接表来管理一对多关系.
开发商:
@OneToMany(cascade = CascadeType.ALL)
@JoinTable(
name="DeveloperGame",joinColumns = @JoinColumn( name="dev_id"),inverseJoinColumns = @JoinColumn( name="game_id")
)
private List
游戏:
@ManyToOne
@JoinTable(
name="DeveloperGame",joinColumns = @JoinColumn( name="game_id"),inverseJoinColumns = @JoinColumn( name="dev_id")
)
private Developer developer;
>如果您不想使用连接表,请删除mappedBy =“developer”并添加@JoinColumn(使关系两侧的连接列具有相同的列名称
开发商:
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "devId")
private List
游戏:
@ManyToOne
@JoinColumn(name = "devId")
private Developer developer;
我想知道这是否是设计或者这是Spring Data REST中的错误.