Jakarta ee javax.ejb.EJBException:尝试向链接表插入数据时事务中止

Jakarta ee javax.ejb.EJBException:尝试向链接表插入数据时事务中止,jakarta-ee,Jakarta Ee,根据这篇文章,我已经实现了基于toString的通用转换器,但是我得到了事务中止异常fk_game_id不能为空。我要做什么才能让它工作 JSF: 控制器bean: @PostConstruct public void init() { this.gameLists = gameFacade.findAll(); this.playerLists = playerFacade.findAll(); this.game = new Game(); this.play

根据这篇文章,我已经实现了基于toString的通用转换器,但是我得到了事务中止异常fk_game_id不能为空。我要做什么才能让它工作

JSF:

控制器bean:

@PostConstruct
public void init() {
    this.gameLists = gameFacade.findAll();
    this.playerLists = playerFacade.findAll();
    this.game = new Game();
    this.player = new Player();

    this.game.setGameId(Integer.SIZE);
    this.player.setPlayerId(Integer.SIZE);

    this.playerGame.setFkGameId(game);
    this.playerGame.setFkPlayerId(player);

}

public String addPlayerGame() {

    this.playerGame = new PlayerGame();
    this.playerGameFacade.create(this.playerGame);


    return "index";
}

您可能需要在addPlayerGame方法中检查控制器中是否正确填充gameId和playerId。对于要在控制器的玩家和游戏对象中填充的playerId和gameId,h:SelectOne菜单是否应如下所示:

<h:selectOneMenu id="fkGameId" value="#{controller.game.gameId}"

如果需要,发布PlayerGameFacade类将有助于进一步调试。

您使用JPA吗?请显示实体beans的代码您是指数据库中的实体类??或控制器管理的beanI是指
播放器
的类声明,
Game
PlayerGame
我的问题中包括了playergameacade现在当我注释掉PlayerGame对象时,我得到了这样的结果:原因:java.lang.IllegalStateException:在同步过程中,通过一个未标记为cascade PERSIST:entities.Game[gameId=32]的关系找到了一个新对象.@DummyGummy更改后,现在我们看到PlayerGame对象填充了正确的数据,因为此异常显示gameId为32(非空)。你能在游戏和玩家对象中分别设置玩家和游戏关系的层叠持久化,然后再试一次吗?还是一样,我已经将所有内容更改为持久化玩家和游戏你能发布玩家、游戏、玩家游戏和玩家游戏吗?
@PostConstruct
public void init() {
    this.gameLists = gameFacade.findAll();
    this.playerLists = playerFacade.findAll();
    this.game = new Game();
    this.player = new Player();

    this.game.setGameId(Integer.SIZE);
    this.player.setPlayerId(Integer.SIZE);

    this.playerGame.setFkGameId(game);
    this.playerGame.setFkPlayerId(player);

}

public String addPlayerGame() {

    this.playerGame = new PlayerGame();
    this.playerGameFacade.create(this.playerGame);


    return "index";
}
<h:selectOneMenu id="fkGameId" value="#{controller.game.gameId}"
<h:selectOneMenu id="fkPlayerId" value="#{controller.player.playerId}"
public String addPlayerGame() {
this.playerGameFacade.create(this.playerGame);
return "index";
}