-
1. Re: EntityHome silently discards updates after errors
gavin.king Oct 31, 2006 11:37 PM (in response to cja987)1) yes, probably EM should have thrown an exception - ask about this in the Hibernate or EJB3 forums
(2) The best way to handle this is to check to see if an instance with the same name exists in the database *first*, rather than trying to do something that you know is possibly going to violate a constraint. -
2. Re: EntityHome silently discards updates after errors
cja987 Nov 1, 2006 3:56 PM (in response to cja987)I should probably clarify, the exception gets thrown the first time, but the second update appeared to succeed when in fact it silently dropped. I've done quite a bit of rearranging now, and haven't reproduced the problem.
As for checking the unique constraint by hand before possibly violating it, I suppose I can live with that, even if it violates DRY. The how of that however is still a bit elusive -- checking it in the action method seems to come too late, because the model values have already been updated, and I get dumped into the debug page due to constraint violations while accessing other components -- namely a datamodel that lists related entities, one of which might actually have the conflicting name.
I tried using a separate entityManager so I wouldn't be reading the current transaction's dirty data, but that didn't pan out either -- the datamodel just ended up null. -
3. Re: EntityHome silently discards updates after errors
cja987 Nov 1, 2006 4:37 PM (in response to cja987)Actually it looks like simply using another EntityManager anywhere in my action bean caused a completely _different_ component (ruleTypes) in the action bean to not be injected. Same result whether I injected it with @PersistenceContext or created it by hand with new EntityManagerFactory().createEntityManager(). I guess using multiple entity managers is verboten.
Things just shouldn't be so difficult. I can't be the first person in the world who has ever had to enforce a uniqueness constraint with JPA. -
4. Re: EntityHome silently discards updates after errors
cja987 Nov 1, 2006 6:08 PM (in response to cja987)I still can't explain the mysterious breakage that started when using another entityManager, but it went away when I switched from a javabean to a SFSB, something I was going to do eventually anyway. I was still seeing dirty data, but I found it was the database I was using -- it looks like HSQLDB only supports Read Uncommitted isolation (it really shouldn't be called isolation at all). Obviously I was going to switch out DB's too .. I guess the moral of the story is to develop for the platform you expect to use sooner rather than later.
If I ever puzzle this out, I'll try submitting a wiki as an example application -- it's the simplest real-world app I can think of where you'd want uniqueness and concurrency control with "retry" options in the UI. -
5. Re: EntityHome silently discards updates after errors
cja987 Nov 1, 2006 8:55 PM (in response to cja987)I'm a dunderhead -- not that this is a big surprise to anyone. It had nothing to do with transaction isolation levels, and everything to do with needing to set flushMode=MANUAL when beginning the conversation. Once I did that, everything works as expected, and entities aren't flushed until I actually tell it to.
I kludged a call to Conversation.instance().changeFlushMode(MANUAL) in a @Create method on RuleHome, because it does have to be available to non-faces requests (quite a lot of my app has to be RESTful). I don't know if there's any more elegant way to do it, since my tinkering with pages.xml wasn't too successful. -
6. Re: EntityHome silently discards updates after errors
gavin.king Nov 1, 2006 9:07 PM (in response to cja987)Your kludge is unnecessary. You should be able to use:
@Create @Begin(flushMode=FlushMode.MANUAL) public void create() {}
If this does not work, please let me know, because it would be a bug in Seam.