-
1. Re: Manually loading an EntityHome
dan.j.allen May 25, 2008 5:51 PM (in response to etaham)Using setInstance() should work fine. The way this class works is that it only queries the database if the instance is null. Then it consults the id. When you use setId(), the instance is set to null internally.
-
2. Re: Manually loading an EntityHome
etaham May 25, 2008 6:08 PM (in response to etaham)Thank you.
-
3. Re: Manually loading an EntityHome
jkronegg Oct 21, 2009 9:04 AM (in response to etaham)When calling EntityHome.setInstance(E), the EntityHome id is not set. This leads to
features
such as:// I have an entity class "MyEntity" with a field "myField", // and a EntityHome class "MyEntityHome" which extends EntityHome // persist a new instance myEntityHome.getInstance().setMyField("test"); myEntityHome.persist(); // myEntityHome.id has been set by the persist to lets say 123 // set a new instance taken from the database MyEntity myEntity = entityManager.find(MyEntity.class, 456); myEntityHome.setInstance(myEntity); // myEntityHome.id is not 456 but is still 123
Changing the MyEntityHome id by calling setId will invalidate the entity by means of a dirty flag. But this does not work the other way round: setInstance does not set/invalidate the EntityHome id.
Is it the expected behavior?
-
4. Re: Manually loading an EntityHome
nickarls Oct 22, 2009 8:36 AM (in response to etaham)Hmm. You could try doing a clearInstance() first, although in normal use I haven't seen any side effects of the id
lagging
(I haven't done finds/refreshes on mutating homes) -
5. Re: Manually loading an EntityHome
zottel Sep 14, 2010 4:42 AM (in response to etaham)I'm currently having a problem that might come from the same source:
I have an entity that is already managed. I want to load this entity into an EntityHome, do stuff with it and then call update() on the EntityHome to save the changes:
public String supersede(TextModule textModule) { this.setInstance(textModule); // ... do stuff return this.update(); }
textModule is the entity, of course.
This leads to a NullPointerException in update().
Is that because the EntityHome's id is null? Do I really have to something like setId(textModule.getId()); getInstance();?
-
6. Re: Manually loading an EntityHome
zottel Sep 14, 2010 5:39 AM (in response to etaham)Uhm ... the actual reason seems to be that this.updatedMessage is null. Huh?!
-
7. Re: Manually loading an EntityHome
zottel Sep 14, 2010 7:29 AM (in response to etaham)Hm, I'm completely at loss now. It's not the updateMessage.
Here's the important part of the stack trace:
Caused by: java.lang.NullPointerException at org.jboss.seam.framework.Controller.debug(Controller.java:197) at org.jboss.seam.framework.Home.updatedMessage(Home.java:54) at org.jboss.seam.framework.EntityHome.update(EntityHome.java:65) at de.sealsystems.ddb.session.TextModuleHome.supersede(TextModuleHome.java:316)
Line 54 of Home.java (according to My Link) is
debug("updated entity #0 #1", getEntityClass().getName(), getId());
But neither getEntityClass() nor its getName() nor getId() return null (I changed the code above to use setId() and getInstance()). I can't figure out what the problem might be. Any hints?
-
8. Re: Manually loading an EntityHome
lvdberg Sep 14, 2010 7:42 AM (in response to etaham)Hi,
have you checked if the logger itself is not null ?
Leo
-
9. Re: Manually loading an EntityHome
zottel Sep 17, 2010 8:17 AM (in response to etaham)Yeah, that's what I figured out, too, meanwhile. I had instantiated the TextModuleHome simply by new TextModuleHome(), so no injection took place (the logger is theoretically injected in the debug class, but as I instantiated the EntityHome object during a response phase, nothing was injected before I tried to use the update() function).
I'm doing what I want to achieve differently now, so now other problems arise. X-)