Trial to get plan.getBuildDefinition() in HibernateEventListener - throws ""could not initialize proxy - no Session""


#1

Hi.
I am developing bamboo add-on.
My add-on listens on BuildCreatedEvent in order to add/change some configuration in task of created plan.
But calling to plan.getBuildDefinition() - I got LazyInitializationException(“could not initialize proxy - no Session”).
According to bamboo-event-listeners
All event listener modules implement the com.atlassian.event.EventListener interface or alternatively the com.atlassian.bamboo.event.HibernateEventListener which will automatically provide you with a hibernate session to access to the database (required for writing notification plugins).

What I miss? How I can do change to configuration of created task?
Thanks.

Snippet of code :
public class CustomListener implements HibernateEventListener {

@Override
public void handleEvent(Event event) {

    if (event instanceof BuildCreatedEvent) {
        BuildCreatedEvent myEvent = (BuildCreatedEvent) event;

        ImmutablePlan plan = planManager.getPlanByKey(myEvent.getPlanKey());
        List<TaskDefinition> tds = plan.getBuildDefinition().getTaskDefinitions(); //here I got exception
       
    }
}

}