[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [eclipselink-users] Problems with ManyToOne and OneToMany
|
Hi,
you have to tell JPA to cascade the persistence operations on the relations.
See for example:
http://wiki.eclipse.org/Introduction_to_EclipseLink_JPA_(ELUG)#.40OneToMany
@OneToMany(mappedBy="team", cascade = {CascadeType.REMOVE})
if you want, that only remove operations will be cascaded.
I hope that helps!
McJoe
Johannes Michler-2 wrote:
>
> Hi,
>
> I'm using eclipselink to do some persistence. I'm having the following
> classes/tables:
>
> @Entity
> public class Team{
> @OneToMany(mappedBy="team")
> public Set<Player> players;
> }
>
> @Entity
> public class Player{
> @ManyToOne
> public Team team;
> }
>
> In my database there is a table team and a table player (with a
> foreign-key-relationship to a team-ID).
>
> This works as far as I'm not deleting anything. But when calling
> em.remove(myPlayer) the "players"-Set in "Team" is not automatically
> updated. When closing my application and restarting it, everything works
> fine. But without this restart the "players"-array seems to get cached
> somewhere.
>
> Any idea on how to solve this? From time to time I'm getting errors that
> there are unpersistet instances after such a remove operation. For
> hibernate, I've read something about an "inverse"-annotation which could
> (if
> I understood it right) solve such a problem.
>
> Any help would be highly appreciated,
>
> best regards
> -Johannes
>
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>
>
--
View this message in context: http://www.nabble.com/Problems-with-ManyToOne-and-OneToMany-tp24447755p24451643.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.