0
私は2つのエンティティ、競争とチームを持っている:JPA ManytoOneと永続ないOneToMany関係
コンクール:
public void setNextCompetitionAttending(Competition nextCompetitionAttending) {
this.nextCompetitionAttending = nextCompetitionAttending;
nextCompetitionAttending.addTeam(this);
}
コンクール:
@Entity
public class Team implements Serializable{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
int id;
@Column(length=255)
String name;
@ManyToOne(optional=true)
Competition nextCompetitionAttending;
List<SiteUser> teamMembers;
nextComeptitionAttendingは、以下の方法で設定されています従って定義される:
@Entity
public class Competition implements Serializable{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
int id;
int maxTeamSize;
String name;
@OneToMany(mappedBy="nextCompetitionAttending")
List<Team> teamsAttending;
私の永続性のコードは次のようになります。データベースで
utx.begin();
EntityManager em = emf.createEntityManager();
em.merge(user);
Competition c = em.find(Competition.class, id);
Team teamon = user.getTeamOn();
teamon.setNextCompetitionAttending(c);
System.out.println("Set next");
em.flush();
utx.commit();
em = emf.createEntityManager();
Team t = em.find(Team.class, teamon.getId());
System.out.println(t.getNextCompetitionAttending());
私はこれをデバッグしようとするために使用してきたコードの末尾のprintlnがあるとして、コラム「NEXTCOMPETITIONATTENDING_ID」は、nullです。
これがなぜ持続しないのですか?
でこの行を置き換えますか? – Lion
どのようなエラーが生じましたか? – Lion
@Lion:IDEはどのように関連していますか? JavaコードはJavaコードです。 NetBeansで作成されているかどうかは関係ありません。 –