I'm new to using ORM tools in enteprise applications. We're building a scaleable application that uses JPA 2.0 and EE6. I'm trying to find a nice pattern to build my application but I can't find a way to keep my entities in sync (I want to pool my beans that access the entities).
An example:
I have a Group:
@Entity
public class Group implements Serializable
{
@Id
private Long id;
@OneToMany
private List<MyUser> myUsers;
public Group()
{
}
public Long getId()
{
return id;
}
public void setId(Long id)
{
this.id = id;
}
public void addUser(MyUser u)
{
myUsers.add(u);
}
}
And I have a user
@Entity
public class MyUser implements Serializable
{
@Id
private Long id;
public MyUser()
{
}
public Long getId()
{
return id;
}
public void setId(Long id)
{
this.id = id;
}
}
Now if I would have a stateless bean that adds or removes users to a group, I risk having another instance of the stateless bean having out of date information. What is the best practice for this?