Spring data-jpa Transactional does not work on service - spring

Here is my service method:
#Resource
private PersonRepository personRepository;
#Transactional
#Override
public Person create(PersonDTO created) {
LOGGER.debug("Creating a new person with information: " + created);
Person person = Person.getBuilder(created.getFirstName(), created.getLastName()).build();
personRepository.save(person);
foo();
return null;
}
public void foo() {
throw new RuntimeException();
}
As you can see i'm throwing an execption but persistancy takes place non the less.
Here is my datasource config:
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" />
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/dbb"/>
<property name="username" value="root" />
<property name="password" value="pass" />
<property name="initialSize" value="10"/>
<property name="maxActive" value="100"/>
<property name="maxIdle" value="15"/>
<property name="minIdle" value="10"/>
<property name="timeBetweenEvictionRunsMillis" value="10000"/>
<property name="minEvictableIdleTimeMillis" value="60000"/>
<property name="validationQuery" value="/* ping */ SELECT 1"/>
<property name="testOnBorrow" value="true"/>
<property name="testWhileIdle" value="true"/>
<property name="removeAbandoned" value="true"/>
<property name="removeAbandonedTimeout" value="300"/>
</bean>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="punit"/>
<property name="dataSource" ref="dataSource"/>
<property name="jpaDialect">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
</property>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="database" value="MYSQL"/>
<!-- <property name="databasePlatform" value="${hibernate.dialect}"/> -->
<property name="showSql" value="false"/>
<property name="generateDdl" value="false"/>
<!-- <property name="hibernate.connection.autocommit" value="false"/> -->
</bean>
</property>
<property name="jpaPropertyMap">
<map>
<entry key="hibernate.connection.autocommit" value="false" />
</map>
</property>
</bean>
Any idea why?
Thanks!

You have to throw TransactionSystemException of Spring. Otherwise, you have to throw own exception that extend TransactionSystemException.
Example :
import org.springframework.transaction.TransactionSystemException;
public class SystemException extends TransactionSystemException {
public SystemException(String message) {
super(message);
}
public SystemException(String message, Throwable throwable) {
super(message, throwable);
}
}
public void foo() {
throw new SystemException("System Error!");
}

Related

Spring boot Keep getting "required a single bean, but 10 were found" although I declared only one service

Whenever I run my spring boot application I keeb getting the following message:
***************************
APPLICATION FAILED TO START
***************************
Description:
Field patchService in org.hisp.dhis.dxf2.metadata.objectbundle.DefaultObjectBundleService required a single bean, but 10 were found:
- org.hisp.dhis.patch.DefaultPatchService#0: defined in URL [file:/D:/001Learning/JavaEE/Projects_FromNet/eagleboard2/eagleboard-services/eagleboard-service-core/target/classes/META-INF/dhis/beans.xml]
- org.hisp.dhis.patch.DefaultPatchService#1: defined in URL [file:/D:/001Learning/JavaEE/Projects_FromNet/eagleboard2/eagleboard-services/eagleboard-service-core/target/classes/META-INF/dhis/beans.xml]
- org.hisp.dhis.patch.DefaultPatchService#2: defined in URL [file:/D:/001Learning/JavaEE/Projects_FromNet/eagleboard2/eagleboard-services/eagleboard-service-core/target/classes/META-INF/dhis/beans.xml]
- org.hisp.dhis.patch.DefaultPatchService#3: defined in URL [file:/D:/001Learning/JavaEE/Projects_FromNet/eagleboard2/eagleboard-services/eagleboard-service-core/target/classes/META-INF/dhis/beans.xml]
- org.hisp.dhis.patch.DefaultPatchService#4: defined in URL [file:/D:/001Learning/JavaEE/Projects_FromNet/eagleboard2/eagleboard-services/eagleboard-service-core/target/classes/META-INF/dhis/beans.xml]
- org.hisp.dhis.patch.DefaultPatchService#5: defined in URL [file:/D:/001Learning/JavaEE/Projects_FromNet/eagleboard2/eagleboard-services/eagleboard-service-core/target/classes/META-INF/dhis/beans.xml]
- org.hisp.dhis.patch.DefaultPatchService#6: defined in URL [file:/D:/001Learning/JavaEE/Projects_FromNet/eagleboard2/eagleboard-services/eagleboard-service-core/target/classes/META-INF/dhis/beans.xml]
- org.hisp.dhis.patch.DefaultPatchService#7: defined in URL [file:/D:/001Learning/JavaEE/Projects_FromNet/eagleboard2/eagleboard-services/eagleboard-service-core/target/classes/META-INF/dhis/beans.xml]
- org.hisp.dhis.patch.DefaultPatchService#8: defined in URL [file:/D:/001Learning/JavaEE/Projects_FromNet/eagleboard2/eagleboard-services/eagleboard-service-core/target/classes/META-INF/dhis/beans.xml]
- org.hisp.dhis.patch.DefaultPatchService#9: defined in URL [file:/D:/001Learning/JavaEE/Projects_FromNet/eagleboard2/eagleboard-services/eagleboard-service-core/target/classes/META-INF/dhis/beans.xml]
Action:
Consider marking one of the beans as #Primary, updating the consumer to accept multiple beans, or using #Qualifier to identify the bean that should be consumed
Process finished with exit code 1
Although Only one Service is declared in the following xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd">
<bean id="org.eagleboard.preheat.PreheatService" class="org.eagleboard.preheat.DefaultPreheatService" scope="prototype">
<aop:scoped-proxy proxy-target-class="false" />
</bean>
<bean id="org.eagleboard.calendar.CalendarService" class="org.eagleboard.calendar.DefaultCalendarService" />
<bean class="org.eagleboard.calendar.impl.Iso8601Calendar" />
<bean class="org.eagleboard.calendar.impl.CopticCalendar" />
<bean class="org.eagleboard.calendar.impl.EthiopianCalendar" />
<bean class="org.eagleboard.calendar.impl.GregorianCalendar" />
<bean class="org.eagleboard.calendar.impl.IslamicCalendar" />
<bean class="org.eagleboard.calendar.impl.NepaliCalendar" />
<bean class="org.eagleboard.calendar.impl.ThaiCalendar" />
<bean class="org.eagleboard.calendar.impl.PersianCalendar" />
<bean id="org.eagleboard.query.planner.QueryPlanner" class="org.eagleboard.query.planner.DefaultQueryPlanner" />
<bean id="org.eagleboard.query.QueryParser" class="org.eagleboard.query.DefaultQueryParser" />
<bean id="org.eagleboard.query.CriteriaQueryEngine" class="org.eagleboard.query.CriteriaQueryEngine" />
<bean id="org.eagleboard.query.InMemoryQueryEngine" class="org.eagleboard.query.InMemoryQueryEngine" />
<bean id="org.eagleboard.query.QueryService" class="org.eagleboard.query.DefaultQueryService" />
<bean class="org.eagleboard.patch.DefaultPatchService" />
<bean id="org.eagleboard.render.RenderService" class="org.eagleboard.render.DefaultRenderService" />
<bean class="org.eagleboard.amqp.RabbitMQAmqpService" />
<bean id="org.eagleboard.interpretation.InterpretationStore" class="org.eagleboard.interpretation.hibernate.HibernateInterpretationStore">
<property name="clazz" value="org.eagleboard.interpretation.Interpretation" />
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!--Eagle Board part-->
<!-- Eagle Board Data Stores -->
<bean id="com.eagleboard.datafield.DataFieldStore" class="org.eagleboard.eagleboard.datafield.hibernate.HibernateDataFieldStore">
<property name="clazz" value="org.eagleboard.eagleboard.datafield.DataField" />
<property name="sessionFactory" ref="sessionFactory" />
<property name="jdbcTemplate" ref="jdbcTemplate" />
<property name="cacheable" value="true" />
</bean>
<bean id="com.eagleboard.fieldset.FieldSetStore" class="org.eagleboard.eagleboard.fieldset.hibernate.HibernateFieldSetStore">
<property name="clazz" value="org.eagleboard.eagleboard.fieldset.FieldSet" />
<property name="sessionFactory" ref="sessionFactory" />
<property name="jdbcTemplate" ref="jdbcTemplate" />
<property name="cacheable" value="true" />
</bean>
<bean id="com.eagleboard.todotask.TodoTaskStore" class="org.eagleboard.eagleboard.todotask.hibernate.HibernateTodoTaskStore">
<property name="clazz" value="org.eagleboard.eagleboard.todotask.TodoTask" />
<property name="sessionFactory" ref="sessionFactory" />
<property name="jdbcTemplate" ref="jdbcTemplate" />
<property name="cacheable" value="true" />
</bean>
<bean id="com.eagleboard.activity.ActivityStore" class="org.eagleboard.eagleboard.activity.hibernate.HibernateActivityStore">
<property name="clazz" value="org.eagleboard.eagleboard.activity.Activity" />
<property name="sessionFactory" ref="sessionFactory" />
<property name="jdbcTemplate" ref="jdbcTemplate" />
<property name="cacheable" value="true" />
</bean>
<bean id="com.eagleboard.project.ProjectStore" class="org.eagleboard.eagleboard.project.hibernate.HibernateProjectStore">
<property name="clazz" value="org.eagleboard.eagleboard.project.Project" />
<property name="sessionFactory" ref="sessionFactory" />
<property name="jdbcTemplate" ref="jdbcTemplate" />
<property name="cacheable" value="true" />
</bean>
<!-- Eagle Board Services -->
<bean id="org.eagleboard.eagleboard.datafield.DataFieldService" class="org.eagleboard.eagleboard.datafield.DefaultDataFieldService">
<property name="dataFieldStore" ref="com.eagleboard.datafield.DataFieldStore" />
</bean>
<bean id="org.eagleboard.eagleboard.fieldset.DefaultFieldSetService" class="org.eagleboard.eagleboard.fieldset.DefaultFieldSetService">
<property name="fieldSetStore" ref="com.eagleboard.fieldset.FieldSetStore" />
<property name="currentUserService" ref="org.eagleboard.user.CurrentUserService" />
</bean>
<bean id="org.eagleboard.eagleboard.todotask.DefaultTodoTaskService" class="org.eagleboard.eagleboard.todotask.DefaultTodoTaskService">
<property name="todoTaskStore" ref="com.eagleboard.todotask.TodoTaskStore" />
<property name="currentUserService" ref="org.eagleboard.user.CurrentUserService" />
</bean>
<bean id="org.eagleboard.eagleboard.activity.DefaultActivityService" class="org.eagleboard.eagleboard.activity.DefaultActivityService">
<property name="activityStore" ref="com.eagleboard.activity.ActivityStore" />
<property name="currentUserService" ref="org.eagleboard.user.CurrentUserService" />
</bean>
<bean id="org.eagleboard.eagleboard.project.DefaultProjectService" class="org.eagleboard.eagleboard.project.DefaultProjectService">
<property name="projectStore" ref="com.eagleboard.project.ProjectStore" />
<property name="currentUserService" ref="org.eagleboard.user.CurrentUserService" />
</bean>
<!-- Eagle Board DeletionHandlers -->
<bean id="org.eagleboard.eagleboard.datafield.DataFieldDeletionHandler" class="org.eagleboard.eagleboard.datafield.DataFieldDeletionHandler">
<property name="jdbcTemplate" ref="jdbcTemplate" />
</bean>
<bean id="org.eagleboard.eagleboard.fieldset.FieldSetDeletionHandler" class="org.eagleboard.eagleboard.fieldset.FieldSetDeletionHandler">
<property name="jdbcTemplate" ref="jdbcTemplate" />
</bean>
<bean id="org.eagleboard.eagleboard.todotask.TodoTaskDeletionHandler" class="org.eagleboard.eagleboard.todotask.TodoTaskDeletionHandler">
<property name="jdbcTemplate" ref="jdbcTemplate" />
</bean>
<bean id="org.eagleboard.eagleboard.activity.ActivityDeletionHandler" class="org.eagleboard.eagleboard.activity.ActivityDeletionHandler">
<property name="jdbcTemplate" ref="jdbcTemplate" />
</bean>
<bean id="org.eagleboard.eagleboard.project.ProjectDeletionHandler" class="org.eagleboard.eagleboard.project.ProjectDeletionHandler">
<property name="jdbcTemplate" ref="jdbcTemplate" />
</bean>
<bean id="org.eagleboard.indicator.IndicatorStore" class="org.eagleboard.indicator.hibernate.HibernateIndicatorStore">
<property name="clazz" value="org.eagleboard.indicator.Indicator" />
<property name="sessionFactory" ref="sessionFactory" />
<property name="cacheable" value="true" />
</bean>
<bean id="org.eagleboard.indicator.IndicatorTypeStore" class="org.eagleboard.common.hibernate.HibernateIdentifiableObjectStore">
<property name="clazz" value="org.eagleboard.indicator.IndicatorType" />
<property name="sessionFactory" ref="sessionFactory" />
<property name="cacheable" value="true" />
</bean>
<bean id="org.eagleboard.indicator.IndicatorGroupStore" class="org.eagleboard.common.hibernate.HibernateIdentifiableObjectStore">
<property name="clazz" value="org.eagleboard.indicator.IndicatorGroup" />
<property name="sessionFactory" ref="sessionFactory" />
<property name="cacheable" value="true" />
</bean>
<bean id="org.eagleboard.indicator.IndicatorGroupSetStore" class="org.eagleboard.common.hibernate.HibernateIdentifiableObjectStore">
<property name="clazz" value="org.eagleboard.indicator.IndicatorGroupSet" />
<property name="sessionFactory" ref="sessionFactory" />
<property name="cacheable" value="true" />
</bean>
<bean id="org.eagleboard.period.PeriodStore" class="org.eagleboard.period.hibernate.HibernatePeriodStore">
<property name="clazz" value="org.eagleboard.period.Period" />
<property name="sessionFactory" ref="sessionFactory" />
<property name="cacheable" value="true" />
<property name="transientIdentifiableProperties" value="true" />
</bean>
<bean id="org.eagleboard.expression.ExpressionStore" class="org.eagleboard.hibernate.HibernateGenericStore">
<property name="clazz" value="org.eagleboard.expression.Expression" />
<property name="sessionFactory" ref="sessionFactory" />
<property name="cacheable" value="true" />
</bean>
<bean id="org.eagleboard.user.UserStore" class="org.eagleboard.user.hibernate.HibernateUserStore">
<property name="sessionFactory" ref="sessionFactory" />
<property name="clazz" value="org.eagleboard.user.User" />
<property name="cacheable" value="true" />
</bean>
<bean id="org.eagleboard.user.CurrentUserStore" class="org.eagleboard.user.hibernate.HibernateCurrentUserStore" />
<bean id="org.eagleboard.user.UserSettingStore" class="org.eagleboard.user.hibernate.HibernateUserSettingStore">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="org.eagleboard.user.UserAuthorityGroupStore" class="org.eagleboard.user.hibernate.HibernateUserAuthorityGroupStore">
<property name="sessionFactory" ref="sessionFactory" />
<property name="clazz" value="org.eagleboard.user.UserAuthorityGroup" />
<property name="cacheable" value="true" />
</bean>
<bean id="org.eagleboard.user.UserCredentialsStore" class="org.eagleboard.user.hibernate.HibernateUserCredentialsStore">
<property name="clazz" value="org.eagleboard.user.UserCredentials" />
<property name="sessionFactory" ref="sessionFactory" />
<property name="cacheable" value="true" />
</bean>
<bean id="org.eagleboard.user.UserGroupStore" class="org.eagleboard.common.hibernate.HibernateIdentifiableObjectStore">
<property name="clazz" value="org.eagleboard.user.UserGroup" />
<property name="sessionFactory" ref="sessionFactory" />
<property name="cacheable" value="true" />
</bean>
<bean id="org.eagleboard.user.UserGroupAccessStore" class="org.eagleboard.hibernate.HibernateGenericStore">
<property name="clazz" value="org.eagleboard.user.UserGroupAccess" />
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="org.eagleboard.user.UserAccessStore" class="org.eagleboard.hibernate.HibernateGenericStore">
<property name="clazz" value="org.eagleboard.user.UserAccess" />
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="org.eagleboard.user.PasswordValidationService" class="org.eagleboard.user.DefaultPasswordValidationService" />
<bean id="org.eagleboard.user.PasswordHistoryValidationRule" class="org.eagleboard.user.PasswordHistoryValidationRule" />
<bean id="org.eagleboard.user.PasswordLengthValidationRule" class="org.eagleboard.user.PasswordLengthValidationRule" />
<bean id="org.eagleboard.user.DigitPatternValidationRule" class="org.eagleboard.user.DigitPatternValidationRule" />
<bean id="org.eagleboard.user.UpperCasePatternValidationRule" class="org.eagleboard.user.UpperCasePatternValidationRule" />
<bean id="org.eagleboard.user.SpecialCharacterValidationRule" class="org.eagleboard.user.SpecialCharacterValidationRule" />
<bean id="org.eagleboard.user.PasswordDictionaryValidationRule" class="org.eagleboard.user.PasswordDictionaryValidationRule" />
<bean id="org.eagleboard.user.UserParameterValidationRule" class="org.eagleboard.user.UserParameterValidationRule" />
<bean id="org.eagleboard.message.MessageConversationStore" class="org.eagleboard.message.hibernate.HibernateMessageConversationStore">
<property name="clazz" value="org.eagleboard.message.MessageConversation" />
<property name="sessionFactory" ref="sessionFactory" />
<property name="jdbcTemplate" ref="jdbcTemplate" />
<property name="statementBuilder" ref="statementBuilder" />
</bean>
<bean id="org.eagleboard.configuration.ConfigurationStore" class="org.eagleboard.hibernate.HibernateGenericStore">
<property name="sessionFactory" ref="sessionFactory" />
<property name="clazz" value="org.eagleboard.configuration.Configuration" />
<property name="cacheable" value="true" />
</bean>
<bean id="org.eagleboard.constant.ConstantStore" class="org.eagleboard.common.hibernate.HibernateIdentifiableObjectStore">
<property name="sessionFactory" ref="sessionFactory" />
<property name="clazz" value="org.eagleboard.constant.Constant" />
<property name="cacheable" value="true" />
</bean>
<bean id="org.eagleboard.scheduling.JobConfigurationStore" class="org.eagleboard.common.hibernate.HibernateIdentifiableObjectStore">
<property name="sessionFactory" ref="sessionFactory" />
<property name="clazz" value="org.eagleboard.scheduling.JobConfiguration" />
<property name="cacheable" value="true" />
</bean>
<bean id="org.eagleboard.deletedobject.DeletedObjectStore" class="org.eagleboard.deletedobject.hibernate.HibernateDeletedObjectStore" />
<bean id="org.eagleboard.version.VersionStore" class="org.eagleboard.version.hibernate.HibernateVersionStore">
<property name="sessionFactory" ref="sessionFactory" />
<property name="clazz" value="org.eagleboard.version.Version" />
<property name="cacheable" value="true" />
</bean>
<bean id="org.eagleboard.metadata.version.MetadataVersionStore"
class="org.eagleboard.metadata.version.hibernate.HibernateMetadataVersionStore">
<property name="sessionFactory" ref="sessionFactory" />
<property name="clazz" value="org.eagleboard.metadata.version.MetadataVersion" />
</bean>
<bean id="org.eagleboard.option.OptionSetStore" class="org.eagleboard.common.hibernate.HibernateIdentifiableObjectStore">
<property name="clazz" value="org.eagleboard.option.OptionSet" />
<property name="sessionFactory" ref="sessionFactory" />
<property name="cacheable" value="true" />
</bean>
<bean id="org.eagleboard.option.OptionStore" class="org.eagleboard.option.hibernate.HibernateOptionStore">
<property name="clazz" value="org.eagleboard.option.Option" />
<property name="sessionFactory" ref="sessionFactory" />
<property name="cacheable" value="true" />
</bean>
<bean id="org.eagleboard.option.OptionGroupStore" class="org.eagleboard.option.hibernate.HibernateOptionGroupStore">
<property name="clazz" value="org.eagleboard.option.OptionGroup" />
<property name="sessionFactory" ref="sessionFactory" />
<property name="cacheable" value="true" />
</bean>
<bean id="org.eagleboard.option.OptionGroupSetStore" class="org.eagleboard.option.hibernate.HibernateOptionGroupSetStore">
<property name="clazz" value="org.eagleboard.option.OptionGroupSet" />
<property name="sessionFactory" ref="sessionFactory" />
<property name="cacheable" value="true" />
</bean>
<bean id="org.eagleboard.legend.LegendSetStore"
class="org.eagleboard.common.hibernate.HibernateIdentifiableObjectStore">
<property name="clazz" value="org.eagleboard.legend.LegendSet" />
<property name="sessionFactory" ref="sessionFactory" />
<property name="cacheable" value="true" />
</bean>
<bean id="org.eagleboard.i18n.I18nLocaleStore" class="org.eagleboard.i18n.hibernate.HibernateI18nLocaleStore">
<property name="clazz" value="org.eagleboard.i18n.locale.I18nLocale" />
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="org.eagleboard.keyjsonvalue.KeyJsonValueStore" class="org.eagleboard.keyjsonvalue.hibernate.HibernateKeyJsonValueStore">
<property name="clazz" value="org.eagleboard.keyjsonvalue.KeyJsonValue" />
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="org.eagleboard.userkeyjsonvalue.UserKeyJsonValueStore"
class="org.eagleboard.userkeyjsonvalue.hibernate.HibernateUserKeyJsonValueStore">
<property name="clazz" value="org.eagleboard.userkeyjsonvalue.UserKeyJsonValue" />
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="org.eagleboard.fileresource.FileResourceStore" class="org.eagleboard.common.hibernate.HibernateIdentifiableObjectStore">
<property name="clazz" value="org.eagleboard.fileresource.FileResource" />
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="org.eagleboard.fileresource.ExternalFileResourceStore"
class="org.eagleboard.fileresource.hibernate.HibernateExternalFileResourceStore">
<property name="clazz" value="org.eagleboard.fileresource.ExternalFileResource" />
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="org.eagleboard.fileresource.FileResourceContentStore" class="org.eagleboard.fileresource.JCloudsFileResourceContentStore">
<property name="configurationProvider" ref="dhisConfigurationProvider" />
<property name="locationManager" ref="locationManager" />
</bean>
<!-- File resource jobs -->
<bean id="org.eagleboard.fileresource.FileResourceUploadCallback" class="org.eagleboard.fileresource.FileResourceUploadCallback" />
<!--<bean id="fileResourceCleanUpJob" class="org.eagleboard.fileresource.FileResourceCleanUpJob" />-->
<!-- Service definitions -->
<!--<bean id="org.eagleboard.dataelement.DataElementGroupService" class="org.eagleboard.dataelement.DefaultDataElementGroupService" />-->
<bean id="org.eagleboard.indicator.IndicatorGroupService" class="org.eagleboard.indicator.DefaultIndicatorGroupService">
<property name="indicatorGroupStore" ref="org.eagleboard.indicator.IndicatorGroupStore" />
</bean>
<!--<bean id="org.eagleboard.dimension.DimensionService" class="org.eagleboard.dimension.DefaultDimensionService" />-->
<bean id="org.eagleboard.fileresource.FileResourceService" class="org.eagleboard.fileresource.DefaultFileResourceService">
<property name="fileResourceStore" ref="org.eagleboard.fileresource.FileResourceStore" />
<property name="fileResourceContentStore" ref="org.eagleboard.fileresource.FileResourceContentStore" />
<property name="schedulingManager" ref="org.eagleboard.scheduling.SchedulingManager" />
<property name="uploadCallback" ref="org.eagleboard.fileresource.FileResourceUploadCallback" />
</bean>
<bean id="org.eagleboard.fileresource.ExternalFileResourceService" class="org.eagleboard.fileresource.DefaultExternalFileResourceService">
<property name="externalFileResourceStore" ref="org.eagleboard.fileresource.ExternalFileResourceStore" />
</bean>
<bean id="org.eagleboard.indicator.IndicatorService" class="org.eagleboard.indicator.DefaultIndicatorService">
<property name="indicatorStore" ref="org.eagleboard.indicator.IndicatorStore" />
<property name="indicatorTypeStore" ref="org.eagleboard.indicator.IndicatorTypeStore" />
<property name="indicatorGroupStore" ref="org.eagleboard.indicator.IndicatorGroupStore" />
<property name="indicatorGroupSetStore" ref="org.eagleboard.indicator.IndicatorGroupSetStore" />
</bean>
<bean id="org.eagleboard.period.PeriodService" class="org.eagleboard.period.DefaultPeriodService">
<property name="periodStore" ref="org.eagleboard.period.PeriodStore" />
</bean>
<bean id="org.eagleboard.expression.ExpressionService" class="org.eagleboard.expression.DefaultExpressionService">
<property name="expressionStore" ref="org.eagleboard.expression.ExpressionStore" />
<property name="dataFieldService" ref="org.eagleboard.eagleboard.datafield.DataFieldService" />
<property name="constantService" ref="org.eagleboard.constant.ConstantService" />
<property name="idObjectManager" ref="org.eagleboard.common.IdentifiableObjectManager" />
</bean>
<bean id="org.eagleboard.user.UserSettingService" class="org.eagleboard.user.DefaultUserSettingService">
<property name="currentUserService" ref="org.eagleboard.user.CurrentUserService" />
<property name="userSettingStore" ref="org.eagleboard.user.UserSettingStore" />
<property name="userService" ref="org.eagleboard.user.UserService" />
<property name="systemSettingManager" ref="org.eagleboard.setting.SystemSettingManager" />
</bean>
PatchService interface:
public interface PatchService
{
Patch diff( PatchParams params );
void apply( Patch patch, Object target );
}
DefaultPatchService.java implementing that interface
public class DefaultPatchService implements PatchService
{
private static final Log log = LogFactory.getLog( DefaultPatchService.class );
private final SchemaService schemaService;
private final QueryService queryService;
private final AmqpService amqpService;
private final MetadataAuditService metadataAuditService;
private final CurrentUserService currentUserService;
private final RenderService renderService;
private final SystemService systemService;
public DefaultPatchService( SchemaService schemaService, QueryService queryService, AmqpService amqpService,
MetadataAuditService metadataAuditService, CurrentUserService currentUserService, RenderService renderService, SystemService systemService )
{
this.schemaService = schemaService;
this.queryService = queryService;
this.amqpService = amqpService;
this.metadataAuditService = metadataAuditService;
this.currentUserService = currentUserService;
this.renderService = renderService;
this.systemService = systemService;
}
...
DefaultObjectBundleService.java in which the DefaultPatchService is Autowired using the interface it implements PatchService which implemented only by it, no other service implementing this interface.
#Service
#Transactional
public class DefaultObjectBundleService implements ObjectBundleService
{
private static final LoggingManager.Logger log = LoggingManager
.createLogger( DefaultObjectBundleService.class );
#Autowired
private CurrentUserService currentUserService;
#Autowired
private PreheatService preheatService;
#Autowired
private SchemaService schemaService;
#Autowired
private SessionFactory sessionFactory;
#Autowired
private IdentifiableObjectManager manager;
#Autowired
private DbmsManager dbmsManager;
#Autowired
private HibernateCacheManager cacheManager;
#Autowired
private Notifier notifier;
#Autowired
private MergeService mergeService;
#Autowired
private DeletedObjectService deletedObjectService;
#Autowired
private PatchService patchService;
#Autowired
private MetadataAuditService metadataAuditService;
#Autowired
private RenderService renderService;
#Autowired
private SystemService systemService;
#Autowired
private AmqpService amqpService;
#Autowired( required = false )
private List<ObjectBundleHook> objectBundleHooks = new ArrayList<>();
#Override
public ObjectBundle create( ObjectBundleParams params )
{
PreheatParams preheatParams = params.getPreheatParams();
if ( params.getUser() == null )
{
params.setUser( currentUserService.getCurrentUser() );
}
preheatParams.setUser( params.getUser() );
preheatParams.setObjects( params.getObjects() );
ObjectBundle bundle = new ObjectBundle( params, preheatService.preheat( preheatParams ), params.getObjects() );
bundle.setObjectBundleStatus( ObjectBundleStatus.CREATED );
bundle.setObjectReferences( preheatService.collectObjectReferences( params.getObjects() ) );
return bundle;
}
...
...
could someone help me, please, also the project have multiple modules, Does dependency between modules have something to do with the problem
I changed the service xml definition from this:
<bean class="org.eagleboard.patch.DefaultPatchService" />
to this:
<bean id="org.eagleboard.patch.PatchService" class="org.eagleboard.patch.DefaultPatchService" />
and the error stopped showing up.
many thanks for all.

Multiple datasource configuration issue

In my project I am using two oracle datasources for one of the datasource Im using LocalSessionFactoryBean and for another LocalContainerEntityManagerFactoryBean
I am mapping the datasources accordingly but when Im trying to get sessionFactory for LocalSessionFactoryBean the datasource details are that of the other. Dono what I am doing wrong.
<tx:annotation-driven transaction-manager="xxxTransactionManager" />
<bean id="xxxEntityManagerFactoryBean"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="persistenceXmlLocation" value="classpath:persistence.xml" />
<property name="jpaDialect">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
</property>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
</property>
<property name="jpaProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
</props>
</property>
</bean>
<bean class="org.modelmapper.ModelMapper" id="modelMapper"/>
<bean id="xxxEntityManager"
class="org.springframework.orm.jpa.support.SharedEntityManagerBean">
<property name="entityManagerFactory" ref="xxxEntityManagerFactoryBean" />
</bean>
<bean id="xxxTransactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="xxxEntityManagerFactoryBean" />
<property name="nestedTransactionAllowed" value="true" />
<property name="dataSource" ref="dataSource" />
<property name="jpaDialect" ref="jpaDialect" />
</bean>
<bean id="jpaDialect" class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
in another xml file that is imported i have
<bean id="sessionFactoryNew"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource1" />
<property name="packagesToScan" value="com.citi.aml.npa.domain.api" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
</props>
</property>
</bean>
<bean id="xxxTransactionManagerNew"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactoryNew" />
<qualifier value="xxxtransaction"/>
</bean>
in app context.xml i have the datasources like
<beans profile="local">
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${db.oracle.driverClassName}" />
<property name="username" value="${db.oracle.username}" />
<property name="password" value="${db.oracle.password}" />
<property name="url" value="${db.oracle.url}" />
</bean>
<context:property-placeholder location="classpath*:/config/local/yyy.properties" ignore-unresolvable="true"/>
</beans>
<beans profile="local">
<bean id="dataSource1" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${db.oracle.driverClassName}" />
<property name="username" value="${db.oracle.username}" />
<property name="password" value="${db.oracle.password}" />
<property name="url" value="${db.oracle.url}" />
</bean>
<context:property-placeholder location="classpath*:/config/local/xxx_db.properties" ignore-unresolvable="true"/>
</beans>
in Dao impl calss i have
#Repository
public class OracledbTestRepository implements TestRepository {
#Autowired
#Qualifier(value = "sessionFactoryNew")
SessionFactory sessionFactory;
#SuppressWarnings("unchecked")
#Override
public List<xxx> getTestData() {
Session session = sessionFactory.getCurrentSession();
System.out.println(sessionFactory);
List<xxx> xxxTestDatas = session.createCriteria(xxx.class).list();
return xxxTestDatas;
}
}
any help will be appreciated.
Your bean configuration looks a bit wonky to me. You have two different profiles with the same name. If these two datasources need to run at the same time, it would be simpler to consolidate your database properties into a single file, and place both datasource configurations within the same profile element.
So, for the consolidated database.properties, do something like:
db1.oracle.url=jdbc:oracle:thin:#server1...
db1.oracle.username=foo
...
db2.oracle.url=jdbc:oracle:thin:#server2...
db2.oracle.username=bar
And for the bean config, use something like:
<beans profile="local">
<context:property-placeholder location="classpath*:/config/local/database.properties" ignore-unresolvable="true"/>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${db1.oracle.driverClassName}" />
<property name="username" value="${db1.oracle.username}" />
<property name="password" value="${db1.oracle.password}" />
<property name="url" value="${db1.oracle.url}" />
</bean>
<bean id="dataSource1" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${db2.oracle.driverClassName}" />
<property name="username" value="${db2.oracle.username}" />
<property name="password" value="${db2.oracle.password}" />
<property name="url" value="${db2.oracle.url}" />
</bean>
</beans>

Configure Multiple JPA Repositories in CrudRepository approach

I am trying to configure the multiple JPA repositories in my web application. Currently I have one Repository as mentioned below. I am using Crud Repository
<jpa:repositories base-package="com.mypackage1" factory-class="org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean" transaction-manager-ref="transactionManager" entity-manager-factory-ref="entityManagerFactory">
<repository:include-filter type="assignable" expression="com.MyFirstRepository"/>
</jpa:repositories>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="com.mypackage1.Model" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="generateDdl" value="true" />
<property name="database" value="H2" />
</bean>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.h2.Driver" />
<property name="url" value="jdbc:h2:database/~test" />
<property name="username" value="sa" />
<property name="password" value="" />
</bean>
If I need to configure multiple repositories,
<bean id="entityManagerFactory2"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource2" />
<property name="packagesToScan" value="com.mypackage2.Model" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="generateDdl" value="true" />
<property name="database" value="H2" />
</bean>
</property>
</bean>
<bean id="transactionManager2" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory2" />
</bean>
<bean id="dataSource2"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.h2.Driver" />
<property name="url" value="jdbc:h2:database/~test2" />
<property name="username" value="sa" />
<property name="password" value="" />
</bean>
I am not able to find any appropriate configuratiuon for this.
Appreciate help on this.

how do i configure spring 2.5.6 + eclipseLink + weblogic 10.3

<bean id="configProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="placeholderPrefix" value="${" />
<property name="placeholderSuffix" value="}" />
<property name="locations">
<value>classpath:ddes/config.properties</value>
</property>
</bean>
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="${datasource}"/>
<property name="resourceRef" value="true"/>
</bean>
<context:load-time-weaver weaver-class="org.springframework.instrument.classloading.weblogic.WebLogicLoadTimeWeaver"/>
<bean id="PersistenceUnit" class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
<property name="defaultDataSource" ref="dataSource"/>
<property name="class">
<!--LIST BEANS-->
<value>....</value>
</property>
</bean>
<bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">
<property name="databasePlatform" value="org.eclipse.persistence.platform.database.OraclePlatform"/>
<property name="generateDdl" value="true"/>
<property name="showSql" value="true"/>
</bean>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="jpaVendorAdapter" ref="jpaVendorAdapter"/>
<property name="persistenceUnitManager" ref="PersistenceUnit"/>
<property name="persistenceUnitName" ref="Persistence-ejbPU"/>
<property name="persistenceProvider" ref="org.eclipse.persistence.jpa.PersistenceProvider"/>
</bean>
<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="transactionManager" ref="entityManagerFactory"/>
</bean>
implement
#CallByReference
#Stateless(mappedName = "cliente")
public class ClienteDAOBean implements ClienteDAOLocal, ClienteDAORemote {
#PersistenceUnit(unitName = "Persistence-ejbPU")
private EntityManagerFactory emf;
public Clientes find(Integer codCliente) throws Exception {
Clientes cliente = null;
EntityManager em = emf.createEntityManager();
try {
javax.persistence.Query q = em.createNamedQuery("Clientes.findByCodCliente").setParameter("codCliente", codCliente);
cliente = (Clientes) q.getSingleResult();
} catch (Exception e) {
throw e;
} finally {
em.close();
return cliente;
}
}
}
Pero al iniciar la aplicaciĆ³n el log arroja este error:
No persistence unit named 'Persistence-ejbPU' is available in scope Persistence-ejbPU.jar
was previously using a persistence.xml file but needed the name of the datasource out dynamic
Simply replace ref with value. Use:
<property name="persistenceUnitName" value="Persistence-ejbPU" />
instead of:
<property name="persistenceUnitName" ref="Persistence-ejbPU"/>
If you are having still problem then I would implement my own LocalContainerEntityManagerFactoryBean class which extends from AbstractEntityManagerFactoryBean so you can override setPersistenceUnitName then see what is going on.

entitymanager is null on DAO class

I am trying to implement Spring MVC 3 +EclipseLink JPA 2
When I call saveUser for example it returns that
NullPointerException, EntityManager is
null
:
public class UserDAO {
#PersistenceContext
private EntityManager em;
public void setEntityManager(EntityManager em) {
this.em = em;
}
#Transactional
public User saveUser(User user){
return em.merge(user);
}
My config is:
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
<property name="dataSource" ref="dataSource"></property>
</bean>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="persistenceUnitName" value="application" />
<property name="jpaVendorAdapter">
<bean
class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">
<property name="showSql" value="true" />
<property name="databasePlatform" value="org.eclipse.persistence.platform.database.MySQLPlatform" />
<property name="generateDdl" value="false" />
</bean>
</property>
<property name="loadTimeWeaver">
<bean
class="org.springframework.instrument.classloading.SimpleLoadTimeWeaver" />
</property>
</bean>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="username" value=".." />
<property name="password" value=".." />
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url"
value="jdbc:mysql://..." />
</bean>
Also have
<context:component-scan base-package="com.elasticbeanstalk.mypackage" />
<context:annotation-config />
It does initialize JPA during Tomcat startup. Why am I see NPE? Could I miss something?
If you instantiate the UserDAO manually, nothing will be injected by Spring. If the DAO is in a package which is under your base-package of <context:component-scan ../> then you can simply autowire it into your Controller. If not, either modify the base-package or also you can define the DAO in the appcontext manually, then you can autowire as well.

Resources