[JBoss Seam] - help with this entity been updated implicitly
by gsegura
Hello everybody,
I have this use case: an item is selected from a list, the edit page for that item is shown, if the save action is invoked some validation is done inside that same method, only if everything is ok I call persist, otherwise the same edit page is redisplayed.
Everything goes fine except one thing: even if validation fails (so I don't call persist) the entity is been updated, why? how? where? I reproduce some code:
@Scope(ScopeType.CONVERSATION)
| @Name("courseEditor")
| @Restrict("#{identity.loggedIn and s:hasRole('Administrator')}")
| public class CourseEditorAction {
|
| @Begin(nested=true)
| public void select(Course selectedCourse) {
| course = entityManager.merge(selectedCourse);
| }
|
| public void save() {
| if(course.getStartDate()!=null && course.getFinishDate()!=null &&
| course.getStartDate().compareTo(course.getFinishDate())>=0) {
| facesMessages.addToControl("finishDate","must be posterior to start date") ;
| ok = false ;
| }
| else {
| sede = entityManager.merge(sede) ;
| if(course.getId()==null)
| //my way to update parent collection of courses (only if course is new)
| sede.getCourses().add(course) ;
| entityManager.persist(course);
| facesMessages.add("Course saved successfully");
| //I only finish conversation in case the edition use case finish
| Conversation.instance().end() ;
| ok = true;
| }
| }
|
| @End
| public void cancel() {}
|
| public boolean isOk() {
| return ok ;
| }
| }
<page view-id="/admin/courseEditor.xhtml">
| <navigation from-action="#{courseEditor.save}">
| <rule if="#{courseEditor.ok}">
| <redirect view-id="/admin/sedeEditor.xhtml"/>
| </rule>
| <rule if="#{not courseEditor.ok}">
| <redirect view-id="/admin/courseEditor.xhtml"/>
| </rule>
| </navigation>
| <navigation from-action="#{courseEditor.cancel}">
| <redirect view-id="/admin/sedeEditor.xhtml"/>
| </navigation>
|
| </page>
if finish date value is before start date, the page is redisplayed, the message describing the incorrect input is shown, but at that moment the course already has been updated :S
I though maybe select method was been called every time the page is redisplayed and since there is a merge that was causing the update, but no: select method is called (makes sense) only first time.
so the updating is invoked somewhere else...
any help is much appreciated
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4110994#4110994
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4110994
18 years, 4 months
[Persistence, JBoss/CMP, Hibernate, Database] - Re: second level cache
by loic
Thanks a lot, i get it worked well.
But i have another matter with cache.
I use my findAll function well, and know i would like to get a subpart of the list putted in cache.
So i created a new function
| public void findTest() {
| // TODO Auto-generated method stub
| em.createQuery("SELECT c FROM FileToSend c where name =?1").setParameter(1,"test").getResultList();
| }
| }
When i use it, even if the resulted entities are already in cache, it connects to the database to get results...
(For the second time call it doesn't... but i need it to get data from cache for the first call).
Any idea on how to do it??
I did test with HibernateSession createFilter function on my first loaded collection but i get an error :
20:04:59,109 ERROR [STDERR] javax.ejb.EJBException: org.hibernate.QueryException
| : The collection was unreferenced
Thanks a lot for helping.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4110993#4110993
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4110993
18 years, 4 months
[JBoss Seam] - @End commits entity changes!
by whafrog
How do I end the conversation without letting hibernate commit the entity changes? Editing is a two stage process: edit, then verify. If I call my action's quit method from the edit page (with immediate="true" on the button), all is fine. If I go to the verify page and make the same call to the quit method, the entities are updated anyway.
Button:
<h:commandButton type="submit" value="Quit without Saving" action="#{myaction.quit}" immediate="true"/>
Method:
@End
| @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
| public String quit()
| {
| logger.debug("Quitting without saving");
| return PAGE_MAIN;
| }
|
If I don't use the @End annotation, nothing is persisted, but then the conversation is out there in memory. Any advice?
Thanks,
Jon
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4110991#4110991
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4110991
18 years, 4 months
[JBoss Messaging] - Re: Delayed Message Sucking
by chip_schoch
anonymous wrote :
| If the messages are on Q2 on L1 the consumer on L1 should receive them all. A clustered queue *always* favours local consumers. I wouldn't expect the consumer on L2 to receive any of them
Hmm... Sometimes it receives all, sometimes some messages. I have been testing by sending 10 messages at a time, 5 are queued to L1-Q1 and 5 are queued to L2-Q1. Each L server has a service that has a local thread pool in which each thread sends a message then calls MessageConsumer.receive() on Q2. All the response messages are queued to L1-Q2 but only half of them are comsumed by the L1 MessageConsumer.receive() threads. The others get consumed by L2-Q2 MessageConsumer.receive(). In the cases when they are not being consumed there is no consumers on L1-Q2 but 5 consumers on L2-Q2. I assumed they should be getting sucked over to L2-Q2. I wonder why they are sometimes.
Could you elaborate on you suggested solution a bit? When you suggest using a clustered temporary queue then aren't I losing my persistence on the response message? Maybe I don't need it?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4110989#4110989
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4110989
18 years, 4 months