Input text gets processed while calling suggestion and its works like designed, because we need to get the value from input.
Thanks. What I am looking for is that the data from the suggestionBox is only put into the inputText-box. The update (I see hibernate-SQL update in the logging) should only be done when clicking Save...
I imagined that the suggestionBox would do this also.
How to do this?
Hello, has this question been answered? I am also having the same problem with the database being updated automatically. Ideally it should update the entity bean property that the value is bound to but not the update database until I save it.
I guess this can unswer your question:
So you should make your entity detached in order to save it manually and then use merge.
Thanks for the links, Ilya.
I've been thinking about how I can get around this problem of premature update and am still very stuck. On my page there are some fields that use the rich:suggestionbox and for which the input value is bound to a Seam managed entity. So whenever I change the value in the suggestionbox, it gets updated automatically in the database. I've thought about several solutions to this problem:
1) Clone a copy of the managed entity. This clone would then be detached which I could bind to the suggestionbox instead of the managed entity. Cloning would be relatively simple if it was just a surface copy, but I need a deep copy since my entity has associations to other entities which are also displayed on the page and can also be edited. This would make cloning a nightmare and which I hope to avoid.
2) Detach the managed entity using Seam. Originally I thought this would be quite simple, but apparently in Seam managed persistence, there is only the enityManager.clear() method which detaches ALL its managed entities which is undesirable. There does not seem to be a way to just detach an entity in Seam, unless I am missing something.
3) Detach the managed entity using Hibernate. I could use session.evict() to detach the entity, but then I run into the LazyInitializationException when the page tries to access the associated entities.
Is there any other way to detach the entity?
1) Cloning is not the best way. I guess if you will choose it you should better try to use DTOs.
2) I know that JPA 1.x enity manager can't do detaching enities. This thing is available in JPA 2.0(EJB 3.1). So definetly you can't use it if you are not using EJB 3.1.
3) The best way to workaround LazyInitializationException is to preload all needed data before detaching entity. And then just use it. You can also try Hibernate.initialize method. It's tricky and even hucky I think. But it works fine.
P.S. This is why I'm not using Seam. Such a complicated and comfortable Java framevork you are trying to use such much more pain you will have in the future with bugs and performance. Because you can't simply change anything in the framework because it's too complicated and finally your code will look like a big workaround. =)
P.S.S. Like an every J2EE developer I like pain all these new things and one day I'll definetly try Seam in my application.