0
내가 두 엔티티하는 경쟁과 팀이 있습니다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로 작성되었는지 여부는 관계 없습니다. –