Merge pull request #118 from PaulLuchyn/master

Resolved InvalidDataAccessApiUsageException
This commit is contained in:
Jeroen Baten 2016-11-09 16:04:44 +01:00 committed by GitHub
commit 2dbd1eb5b7
5 changed files with 45 additions and 29 deletions

View file

@ -249,7 +249,7 @@
</type>
</property>
<many-to-one name="orderElement" column="order_element_id" lazy="false"/>
<many-to-one name="orderElement" column="order_element_id" />
<one-to-one name="taskSource" class="TaskSource" cascade="delete" access="field"
property-ref="schedulingData" />
@ -264,8 +264,7 @@
<version name="version" access="property" type="long" />
<many-to-one name="schedulingData" class="SchedulingDataForVersion" cascade="none" unique="true" access="field"
lazy="false" />
<many-to-one name="schedulingData" class="SchedulingDataForVersion" cascade="none" unique="true" access="field" />
<one-to-one name="task" class="org.libreplan.business.planner.entities.TaskElement" constrained="true"
cascade="delete" access="field" lazy="false"/>

View file

@ -41,7 +41,7 @@
<!-- Indexed -->
<many-to-one name="parent" class="TaskGroup" cascade="none" column="parent"
index="idx_task_element_on_task_group" lazy="false" />
index="idx_task_element_on_task_group" />
<one-to-one name="taskSource" cascade="delete" />
@ -100,7 +100,7 @@
class="org.libreplan.business.planner.entities.consolidations.Consolidation" cascade="all"/>
<!-- Indexed on the other side -->
<set name="resourceAllocations" cascade="all-delete-orphan" lazy="false">
<set name="resourceAllocations" cascade="all-delete-orphan" >
<key column="task" />
<one-to-many class="ResourceAllocation" />
</set>
@ -126,7 +126,7 @@
</list>
</joined-subclass>
<joined-subclass name="TaskMilestone" table="task_milestone">
<joined-subclass name="TaskMilestone" table="task_milestone" >
<key column="task_element_id"/>
<component name="startConstraint">

View file

@ -38,6 +38,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
@ -72,7 +73,15 @@ public class SendEmailOnMilestoneReached implements IEmailNotificationJob {
@Autowired
EmailConnectionValidator emailConnectionValidator;
/**
* Transactional here is needed because without this annotation we are getting
* "LazyInitializationException: could not initialize proxy - no Session" error,
* when "item.getParent().getOrderElement().getOrder().getResponsible()" method was called.
* Earlier this trouble was not present because in Tasks.hbm.xml for "TaskElement" class field
* named "parent", which has relation "many-to-one" to "TaskGroup", lazy was set to "false".
*/
@Override
@Transactional
public void sendEmail() {
// Gathering data
checkMilestoneDate();
@ -108,11 +117,13 @@ public class SendEmailOnMilestoneReached implements IEmailNotificationJob {
emailNotificationModel.setUpdated(new Date());
String responsible = "";
if ( item.getParent().getOrderElement().getOrder().getResponsible() != null )
if ( item.getParent().getOrderElement().getOrder().getResponsible() != null ) {
responsible = item.getParent().getOrderElement().getOrder().getResponsible();
}
User user = null;
try {
// FIXME: Code below can produce NullPointerException if "Responsible" field is not set in Project Details -> General data
user = userDAO.findByLoginName(responsible);
} catch (InstanceNotFoundException e) {
e.printStackTrace();

View file

@ -20,6 +20,8 @@
package org.libreplan.importers.notifications.realization;
import org.joda.time.DateTime;
import org.joda.time.DateTimeComparator;
import org.libreplan.business.common.Configuration;
import org.libreplan.business.email.entities.EmailNotification;
import org.libreplan.business.email.entities.EmailTemplateEnum;
@ -66,7 +68,15 @@ public class SendEmailOnTaskShouldFinish implements IEmailNotificationJob {
@Autowired
private EmailConnectionValidator emailConnectionValidator;
/**
* Transactional here is needed because without this annotation we are getting
* "LazyInitializationException: could not initialize proxy - no Session" error,
* when "item.getAllResourceAllocations()" method was called.
* Earlier this trouble was not present because in Tasks.hbm.xml for joined subclass "Task" field
* named "resourceAllocations", which has relation "one-to-many" to "ResourceAllocation", lazy was set to "false".
*/
@Override
@Transactional
public void sendEmail() {
// Gather data for email sending
taskShouldFinish();
@ -97,23 +107,15 @@ public class SendEmailOnTaskShouldFinish implements IEmailNotificationJob {
@Transactional
public void taskShouldFinish() {
// TODO resolve deprecated
// Check if current date equals with item date
Date date = new Date();
int currentYear = date.getYear();
int currentMonth = date.getMonth();
int currentDay = date.getDay();
DateTime currentDate = new DateTime();
DateTimeComparator dateTimeComparator = DateTimeComparator.getDateOnlyInstance();
List<TaskElement> tasks = taskElementDAO.getTaskElementsWithParentsWithoutMilestones();
for (TaskElement item : tasks){
Date endDate = item.getEndDate();
int endYear = endDate.getYear();
int endMonth = endDate.getMonth();
int endDay = endDate.getDay();
DateTime endDate = new DateTime(item.getEndDate());
if ( currentYear == endYear &&
currentMonth == endMonth &&
currentDay == endDay ) {
if ( dateTimeComparator.compare(currentDate, endDate) == 0 ) {
// Get all resources for current task and send them email notification
sendEmailNotificationAboutTaskShouldFinish(item);
}

View file

@ -19,6 +19,8 @@
package org.libreplan.importers.notifications.realization;
import org.joda.time.DateTime;
import org.joda.time.DateTimeComparator;
import org.libreplan.business.common.Configuration;
import org.libreplan.business.email.entities.EmailNotification;
@ -66,7 +68,15 @@ public class SendEmailOnTaskShouldStart implements IEmailNotificationJob {
@Autowired
private EmailConnectionValidator emailConnectionValidator;
/**
* Transactional here is needed because without this annotation we are getting
* "LazyInitializationException: could not initialize proxy - no Session" error,
* when "item.getAllResourceAllocations()" method was called.
* Earlier this trouble was not present because in Tasks.hbm.xml for joined subclass "Task" field
* named "resourceAllocations", which has relation "one-to-many" to "ResourceAllocation", lazy was set to "false".
*/
@Override
@Transactional
public void sendEmail() {
// Gather data
taskShouldStart();
@ -98,20 +108,14 @@ public class SendEmailOnTaskShouldStart implements IEmailNotificationJob {
@Transactional
public void taskShouldStart() {
// Check if current date equals with item date
Date date = new Date();
// TODO resolve deprecated
int currentYear = date.getYear();
int currentMonth = date.getMonth();
int currentDay = date.getDay();
DateTime currentDate = new DateTime();
DateTimeComparator dateTimeComparator = DateTimeComparator.getDateOnlyInstance();
List<TaskElement> tasks = taskElementDAO.getTaskElementsWithParentsWithoutMilestones();
for (TaskElement item : tasks) {
Date startDate = item.getStartDate();
int startYear = startDate.getYear();
int startMonth = startDate.getMonth();
int startDay = startDate.getDay();
DateTime startDate = new DateTime(item.getStartDate());
if ( currentYear == startYear && currentMonth == startMonth && currentDay == startDay ) {
if ( dateTimeComparator.compare(currentDate, startDate) == 0) {
// Get all resources for current task and send them email notification
sendEmailNotificationAboutTaskShouldStart(item);
}