persistence@glassfish.java.net

Re: Cycle In Object Graph

From: Craig L Russell <Craig.Russell_at_Sun.COM>
Date: Sun, 04 Feb 2007 20:54:10 -0800

Hi,

On Feb 4, 2007, at 7:00 PM, Soe Moe Kyaw @ Stephen Wang wrote:

> Hi All,
>
> How can I prevent cycle in object graph between two entities which
> have BI Directional OneToMany relationship?

There is no problem with the cycle in the object graph. It will not
be an issue with either persistence or serialization.

Craig
>
> Here are the codes;
>
> public class Realm implements Serializable{
>
> @Id
> @GeneratedValue(strategy = GenerationType.SEQUENCE,
> generator="REALM_ID_GENERATOR")
> @SequenceGenerator(name="REALM_ID_GENERATOR")
> private Long id;
>
> private String realmName;
>
> private String description;
>
> @OneToMany(cascade = CascadeType.ALL, mappedBy = "realm",
> fetch=FetchType.LAZY)
> private Collection<User> users;
> ......
> }
>
> public class User implements Serializable {
>
> @Id
> @GeneratedValue(strategy = GenerationType.SEQUENCE, generator =
> "USER_ID_GENERATOR")
> @SequenceGenerator(name="USER_ID_GENERATOR")
> private Long id;
>
> private String userName;
>
> private String description;
>
> @ManyToOne()
> @JoinColumn(name="realm_id")
> private Realm realm;
> ....
> }
>
>
> --
> Regards;
> Soe Moe Kyaw @ Stephen Wang

Craig Russell
Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
408 276-5638 mailto:Craig.Russell_at_sun.com
P.S. A good JDO? O, Gasp!