|
|
|
|
(no subject) [message #682339 is a reply to message #629336] |
Fri, 10 June 2011 21:14 |
Eclipse User |
|
|
|
Originally posted by:
I have similar problem. However I have one side of relationship mapped:
@Entity
public class UserEntity implements Serializable {
/*...*/
@ManyToMany(mappedBy = "owners")
private List<AppEntity> ownedApps;
public List<AppEntity> getOwnedApps() {
return ownedApps;
}
/*...*/
}
@Entity
public class AppEntity implements Serializable {
/*...*/
@ManyToMany
private List<UserEntity> owners;
public void addOwner(UserEntity owner) {
owners.add(owner);
}
public List<UserEntity> getOwners() {
return owners;
}
/*...*/
}
In my startup Bean, that is invoked on app startup I have something like that:
@Singleton
@Startup
public class ConfigBean {
/*...*/
@PersistenceContext
private EntityManager em;
@PostConstruct
public void createData() {
/*...*/
UserEntity admin = new UserEntity();
em.persist(admin);
AppEntity someapp = new AppEntity();
em.persist(somegame);
somegame.addOwner(admin);
/*...*/
}
}
Where em is EntityManager managed by web container.
Now interesting things happen. I'm running this on Glassfish 3. After starting the app, someapp.getOwners() returns list with one element, admin UserEntity, as intended. However, admin.getOwnedApps() returns empty list.
If I disable and then enable the app in Glassfish, admin.getOwnedApps() runs properly and returns list with someapp.
The most interesting thing is however, that if I run Glassfish in debug mode (I start it from NetBeans) i get proper output from admin.getOwnedApps() without disabling and reenabling the app.
It seems that some weird caching is present in normal mode and not in debug mode. What should I do to be sure, that it runs properly from the beginning?
(Adding em.flush() after somegame.addOwner(admin); doesn't work.)
|
|
|
Re: (no subject) [message #683422 is a reply to message #682338] |
Mon, 13 June 2011 17:45 |
|
In general you have to maintain bi-directional relationships, otherwise your object model will be out of date.
The issue probably works in the debug mode because the default cache type uses soft reference which are probably getting garbage collected.
James : Wiki : Book : Blog : Twitter
|
|
|
|
Powered by
FUDForum. Page generated in 0.04483 seconds