LazyInit Exception when Refreshing a page on Alfresco 3 (Hibernate 3 + Spring) - java

I got the following issue on the specific layer we have on Alfresco (version 3, using hibernate 3 + spring):
When a page is first loaded, everything goes fine. No problem.
When we do an interaction on this page that leads to a refresh, we have some
lazyinitializationexception could not initialize proxy - no session.
I know the lazyinit is a common issue. But because of the fact that we want only make changes on the specific layer not on the alfresco layer, many resolutions can't be applied.
The one consisting in forcing the sessions to stay open is not possible for us.
The one using Hibernate.Initialize leads to this error:
User:admin ERROR [org.hibernate.LazyInitializationException] failed to lazily initialize a collection of role: org.jbpm.taskmgmt.exe.TaskInstance.variableInstances, no session or session was closed
So I got three questions:
Does someone has an idea of why on the first load, we have no problem and on refresh we got the lazyInit Exception ?
How could we make the hibernate.initialize work ?
Is there any other way to solve this issue ?
To say a little more about the context:
We want to show to user via IHM the task history. To do that we fill a table, to do so we collect the current taskInstance ti and the previous ones and for each of them we do a ti.GetName(), ti.GetDescription(), etc. The issue seems to come that after collecting the Task Instances, the hibernate session is close, so we can't perform ti.GetName() and other operations on ti.
In advance thank you all for your help,
Regards

Okay, after a lot of days of working on that, we just found how to solve it. A colleague just solve it when I was writing the desperate post :)
So the solution was to use
getHibernateTemplate().Hibernate.Initialize(ti.GetName());
directly in the Callback part of the DAO class.
Hope it will be useful to others and thanks for your efforts to help and I'm always unsure on whether I should post code or not to keep the post simple.

Related

Spring StateMachine How do I know if a transistion is rejected due to failed guard or action?

I have the same question as in the topic below, but I'm not so sure if my approach is wrong.
How do I know if a guard rejected a transistion
My app is a linear step-by-step strategy board game with several different game settings. I've decided to use Spring StateMachine to solve as in my opinion (and so far) it solves a lot little code-related organisational problems But now I'm stacked
The problem I have run into is that I can't say if my event passed all the guards and transition occurs. I just get true-flag when an event is added to the queue
The approach I'm following is passing data via event-context, validation of one with guards and apply changes using actions
transitions
.withExternal().source(SPEECHES).target(VOTING).event(VOTING_EVENT)
.guard(Guard.and(
guards.get(NoVotesFromSuspectedGuard.QUALIFIER),
guards.get(NoSelfVotingGuard.QUALIFIER),
guards.get(NoDeadParticipantsVotingGuard.QUALIFIER),
guards.get(NoVotingForDeadParticipantsGuard.QUALIFIER),
votingOutOfParticipantListGuardFactory.get(NUMBER_OF_PLAYERS),
guards.get(VotingBasedOnPreviousOneGuard.QUALIFIER)
))
.action(actions.get(CalculateVotingAction.QUALIFIER))
As I understand now, there is no possibility to notify event-supplier about failed guard evaluation. If so, just let me know and I will switch to another SM implementation. But if there is any possibility of solving my problem, please help me.
The behaviour I expect is any meta info of failed guard (to build formatted error message)
You can use some context flag, for example context.put("NoVotesFromSuspectedGuard", false) when "NoVotesFromSuspectedGuard" isn't success and then you can check this variable in your invoke code context.getExternalVariables().get("NoVotesFromSuspectedGuard", Boolean.class).
Also, in Spring State Machine you can declare ActionListener bean, which contains some different methods for StateMachine events monitoring.
For more information, you can see Habr(Russian)

Vaadin Push not working in 10 (flow)

In Vaadin 8, I am able to asynchronously update a Grid with incoming websocket data using the access method of UI, which locks the thread and performs the updates, then pushes them without the client having to request it.
access(() -> addMessage(message));
I am trying to use vaadin 10 now, and since the main class you start with doesn't extend UI, I am trying to do it like this:
UI.getCurrent().access((Command) () -> addTrade(message))
However it is not working, and you have to click somewhere on the page for the update to happen. I have the #Push annotation on the class, so I believe server push should work.. thank you so much guys!
in my servlet:
asyncSupported = true
have also tried this.getUI().get().access(), still not updating.
This is most likely caused by https://github.com/vaadin/flow/issues/3256 that is currently being fixed.
The tickets also suggests a workaround: grid.getElement().getNode().markAsDirty();. If the workaround solves the issue, then it's very likely caused by that bug. If not, then there's some other issue that would require further investigation.

SessionMap does not save the objects JSF

In my application the objects put into sessionMap doesn't stored. I can access it in the same object where I have done the put operation, but when I want to do it from another bean, the object doesn't exist. I put the objects into the session in the following way:
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put( "myKey", myObject );
This is the first time that happens. In another apps I can access the objects stored in the sessionMap.
Best Regards
DrakoRod
Thanks for your help, finally I resolved the problem, really a don't saw exactly what's was. I explain what I did.
First. My project was in a normal template with this frameworks: JSF 2, primefaces, Spring, Hibernate and log4j. So, all was going well. I added a new template to project and happened the problem with session.
But I just copy/paste code in menu, so I decided write tag by menu's tag and vuala! everything worked.
How I say, I don't saw what's was the problem, but I solved it.

Use transactional sessions activemq

http://activemq.apache.org/hello-world.html
In the above link author suggest to try transactional sessions, but unfortunately after lots of search on internet not able to get what transactional sessions mean.
And what are its pre-requisite??
The links that i read are:
http://activemq.apache.org/how-do-transactions-work.html
http://activemq.apache.org/should-i-use-transactions.html
Unfortunately still not able to get the meaning and particularly implementation of transactional session and why to use it.
Can any one provide sample reference implementation or tutorial for same. ?
Unfortunately still not able to get the meaning and particularly implementation of transactional session and why to use it.
Its simple if you want to perform an operation on a message , you received a message and did operation if the output is not correct , you dont want to proceed.
let me check for implementation will send if I find on my previous project

Creating user events on certain actions. What is recommended solution?

This question regards how one can effectively create and persist event domain objects on certain system or user triggered events which themselves may or may not persist changes to the database.
Im creating a system where a user can tag some object, and when tagging occurs i should create a UserTagEvent which holds the object that was tagged, the tag that was applied or removed, and the user that tagged the object. (EDIT: This is not the actual TAG object, just a log of a tagging event)
The relationship of such a taggable object is one-to-many (a taggable object has many tags)
As far as i can see i have three alternatives.
Inline code in the controller/service which does the tagging (don't wanna do this as it mixes two different business processes.)
Use hibernate listeners pre-collection-update and post-collection-update to fetch the necessary information and create and persist a new UserTagEvent
Use AOP.
Do i have any other alternatives? Has anyone done something similar to this? What do you guys think i should do? Any help is appreciated.
It is not 100% clear if the UserTagEvent represents the actual tag or if it just acts as a log for a tag event.
Use hibernate listeners pre-collection-update and post-collection-update to fetch the necessary information and create and persist a new UserTagEvent
If the UserTagEvent is your tag the hibernate listeners would not make much sense because they would only get fired when you create a UserTagEvent and add it to the object by yourself and then you won nothing.
Inline code in the controller/service which does the tagging (don't wanna do this as it mixes two different business processes.)
I would start by creating a TagService that is responsible for tagging/tag-logging. You could use it either from a controller or by using it from aop but you should encapsule the functionality like: tagService.createTag(tag, object, user)
This could be handy especially when you later want to use a different technology to store the events like some nosql solution.
The following is what i learned when exploring my options:
1) Inline code in the controller/service which does the
tagging (don't wanna do this as it
mixes two different business
processes.)
Didnt give this alternative a try
2) Use hibernate listeners pre-collection-update and
post-collection-update to fetch the
necessary information and create and
persist a new UserTagEvent
This turned out to be very difficult, inefficient, and problematic for several reasons.
For example, you are working with a collection of items which may or may not be lazy initialized. In order to detect changes in the collection i had to listen for collection initialization event, get a cloned collection, store it to a field variable, then listen for a update collection event, get a cloned collection and compare with the collection previously stored.
In addition these events got fired for ALL hibernate events, not just for the domain objects i was interested in. So this was a "no go"...
3) Use AOP.
I was originally very optimistic about this solution, and after a few tries i soon came to realize that this wasn't as simple as i first thought. There were very few guides on the web describing Grails AND AOP, and those existed were rather old.
There was a lot more work involved than i originally thought. My overall impression is that grails seems to have a lot of bugs assosciated with AOP integration, and i also didn't like the fact that i had to add bean definitions to resources.groovy for each aspect that i created. I tried to make aspects be autoloaded through annotations (auto-proxy), but with no luck.
In addition i never got the pointcut to work outside the main project. As my tagging solution is defined as a grails plugin it seems that AOP can't be applied on classes of the plugin (even if it is a inplace plugin).
So this turned out to be a "no go" aswell
So drum roll please.
What i ended up with was using the observer pattern to fire off an event whenever a new tag was added or removed. This involved making changes to my tagger plugin where i could specify listeners through spring beans (whicn implemented a TagEventListener interface) and have the tagger plugin fire off events on the spring beans upon the addTag and removeTag method calls.
Overall im pretty happy with this solution, it involves one or two more method calls then what would be necessary if i had just inlined as described in option 1. But this way I have cleaner code, and i don't mix business processes. So i think the extra 1ns overhead is worth it.

Categories

Resources