-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: the Problem with hibernate annotation many-to-many
PostPosted: Tue Apr 06, 2010 4:53 am 
Newbie

Joined: Tue Apr 06, 2010 4:45 am
Posts: 1
have pojo class A and B
public class A {
@Id
@GeneratedValue
private Integer id;
private String name;

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

@ManyToMany(cascade={CascadeType.MERGE,CascadeType.PERSIST}
)
@JoinTable(name="a_b",
joinColumns={@JoinColumn(name="a_id")},
inverseJoinColumns={@JoinColumn(name="b_id")}
)
private List<B> bs;

public List<B> getBs() {
return bs;
}

public void setBs(List<B> bs) {
this.bs = bs;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

}


@Entity
@Table(name="a")
@Entity
@Table(name = "b")
public class B {
@Id
@GeneratedValue
private Integer id;
private String name;

@ManyToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE }, mappedBy = "bs", targetEntity = A.class)
private List<A> as;

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public List<A> getAs() {
return as;
}

public void setAs(List<A> as) {
this.as = as;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

}

the problem is I can use
a.getBs();
but I can't use
b1.getAs();


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.