I'm using springboot and spring-data-jdbc.
I wrote this repository class
#Repository
#Transactional(rollbackFor = Exception.class)
public class RecordRepository {
public RecordRepository() {}
public void insert(Record record) throws Exception {
JDBCConfig jdbcConfig = new JDBCConfig();
SimpleJdbcInsert messageInsert = new SimpleJdbcInsert(jdbcConfig.postgresDataSource());
messageInsert.withTableName(record.tableName()).execute(record.content());
throw new Exception();
}
}
Then I wrote a client class that invokes the insert method
#EnableJdbcRepositories()
#Configuration
public class RecordClient {
#Autowired
private RecordRepository repository;
public void insert(Record r) throws Exception {
repository.insert(r);
}
}
I would expect that no record are insert to db when RecordClient's insert() method is invoked, because RecordRespository's insert() throws Exception. Instead the record is added however.
What am I missing?
EDIT. This is the class where I configure my Datasource
#Configuration
#EnableTransactionManagement
public class JDBCConfig {
#Bean
public DataSource postgresDataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("org.postgresql.Driver");
dataSource.setUrl("jdbc:postgresql://localhost:5432/db");
dataSource.setUsername("postgres");
dataSource.setPassword("root");
return dataSource;
}
}
You have to inject your datasource instead of creating it manually. I guess because #Transactional only works for Spring managed beans. If you create a datasource instance by calling new constructor (like this new JDBCConfig(). postgresDataSource()), you are creating it manually and it's not a Spring managed beans.
#Repository
#Transactional(rollbackFor = Exception.class)
public class RecordRepository {
#Autowired
DataSource dataSource;
public RecordRepository() {}
public void insert(Record record) throws Exception {
SimpleJdbcInsert messageInsert = new SimpleJdbcInsert(dataSource);
messageInsert.withTableName(record.tableName()).execute(record.contents());
throw new Exception();
}
}
Related
I have done a sample application with springboot to connect with two databases using the below reference
https://dzone.com/articles/multiple-mongodb-connectors-with-spring-boot
I can access data from different databases using repository interfaces which extends MongoRepository
But i want to access data using MongoOperations as below how to differentiate between two databases
#RestController
#RequestMapping(value = "/sample")
public class SampleController {
private final PrimaryRepository primaryRepository;
private final SecondaryRepositor secondaryRepository;
#Autowired
MongoOperations mongoOps;
#Autowired
public SampleController(PrimaryRepository primaryRepository, SecondaryRepositor secondaryRepository) {
this.primaryRepository = primaryRepository;
this.secondaryRepository = secondaryRepository;
}
#RequestMapping(method = RequestMethod.GET)
public void sample() {
log.info("************************************************************");
log.info("Start printing mongo objects");
log.info("************************************************************");
primaryRepository.save(new PrimaryModel(null, "Primary database plain object"));
secondaryRepository.save(new SecondaryModel(null, "Secondary database plain object"));
List<PrimaryModel> primaries = primaryRepository.findAll();
for (PrimaryModel primary : primaries) {
log.info(primary.toString());
}
List<SecondaryModel> secondaries = secondaryRepository.findAll();
**List<SecondaryModel> second = mongoOps.findAll(SecondaryModel.class);**
log.info("RES: {}",second);
for (SecondaryModel secondary : secondaries) {
log.info(secondary.toString());
}
log.info("************************************************************");
log.info("Ended printing mongo objects");
log.info("************************************************************");
}
}```
You need to use #Qualifier to get desired MongoDB instance.
#Autowired
#Qualifier("primaryMongoTemplate")
MongoOperations primaryMongoOps;
#Autowired
#Qualifier("secondaryMongoTemplate")
MongoOperations secondaryMongoOps;
Note:
You don't need public SampleController(PrimaryRepository primaryRepository, SecondaryRepositor secondaryRepository), use instead:
#RestController
#RequestMapping(value = "/sample")
public class SampleController {
#Autowired
PrimaryRepository primaryRepository;
#Autowired
SecondaryRepositor secondaryRepository;
#Autowired
#Qualifier("primaryMongoTemplate")
MongoOperations primaryMongoOps;
#Autowired
#Qualifier("secondaryMongoTemplate")
MongoOperations secondaryMongoOps;
#RequestMapping(method = RequestMethod.GET)
public void sample() {
...
Can you try below configuration to use multiple database with MongoOperation
#Configuration
#EnableMongoRepositories(basePackages={"com.company.repo.dbOne"}, mongoTemplateRef="mongoTemplateOne")
public class AbcRepoConfiguration {
#Bean(name="mongoPropertiesOne")
#ConfigurationProperties
public MongoProperties mongoProperties() {
return new MongoProperties();
}
#Bean(name="mongoPropertiesOne")
public SimpleMongoDbFactory mongoDbFactory(MongoClient mongo, #Qualifier("mongoPropertiesOne") MongoProperties mongoProperties) throws Exception {
String database = this.mongoProperties.getMongoClientDatabase();
return new SimpleMongoDbFactory(mongo, database);
}
#Bean(name="mongoTemplateOne")
public MongoTemplate mongoTemplate(#Qualifier("mongoTemplateOne") MongoDbFactory mongoDbFactory, MongoConverter converter) throws UnknownHostException {
return new MongoTemplate(mongoDbFactory, converter);
}
}
#Configuration
#EnableMongoRepositories(basePackages={"com.company.repo.dbTwo"}, mongoTemplateRef="mongoTemplateTwo")
public class AbcRepoConfiguration {
#Bean(name="mongoPropertiesTwo")
#ConfigurationProperties
public MongoProperties mongoProperties() {
return new MongoProperties();
}
#Bean(name="mongoPropertiesTwo")
public SimpleMongoDbFactory mongoDbFactory(MongoClient mongo, #Qualifier("mongoPropertiesTwo") MongoProperties mongoProperties) throws Exception {
String database = this.mongoProperties.getMongoClientDatabase();
return new SimpleMongoDbFactory(mongo, database);
}
#Bean(name="mongoTemplateTwo")
public MongoTemplate mongoTemplate(#Qualifier("mongoTemplateTwo") MongoDbFactory mongoDbFactory, MongoConverter converter) throws UnknownHostException {
return new MongoTemplate(mongoDbFactory, converter);
}
}
You can create two MongoOperations bean. You can replace replace localhost with the DB machine IP Address. if you have sharded cluster you can change below implementation new MongoClient(new MongoClientURI("mongodb://host1:27017,host2:27017"));
#Configuration
class MongoConfiguration {
#Bean
public MongoClient mongo() {
return new MongoClient("localhost", 27017); // server address, port
}
#Bean
#Qualifier("firstDatabase")
public MongoTemplate mongoTemplate() throws Exception {
return new MongoTemplate(mongo(), "test1Db"); // test1Db is database name
}
#Bean
#Qualifier("secondDatabase")
public MongoTemplate mongoTemplate() throws Exception {
return new MongoTemplate(mongo(), "test2Db");
}
}
Now in your controller, you can inject both MongoTemplate and connect to the respective database.
#Autowired
#Qualifier("firstDatabase")
MongoOperations mongoOps1;
#Autowired
#Qualifier("secondDatabase")
MongoOperations mongoOps2;
I am trying to integrate Hibernate 5.2.12 into my Spring application but am getting a nullPointerException when get a session.
Here is the Hibernate configuration
#Configuration
#EnableTransactionManagement
public class HibernateConfig {
#Bean
public LocalSessionFactoryBean sessionFactory() {
System.out.println("Session factory called!");
LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
sessionFactory.setDataSource(dataSource());
sessionFactory.setPackagesToScan(
"com.app.persistence.model");
sessionFactory.setHibernateProperties(hibernateProperties());
return sessionFactory;
}
#Bean
public DataSource dataSource() {
BasicDataSource dataSource = new BasicDataSource();
dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
dataSource.setUrl("jdbc:mysql://localhost:3306/appDatabase?useSSL=false");
dataSource.setUsername("root");
dataSource.setPassword("password");
return dataSource;
}
#Bean
public PlatformTransactionManager hibernateTransactionManager() {
HibernateTransactionManager transactionManager
= new HibernateTransactionManager();
transactionManager.setSessionFactory(sessionFactory().getObject());
return transactionManager;
}
private final Properties hibernateProperties() {
Properties hibernateProperties = new Properties();
hibernateProperties.setProperty(
"hibernate.hbm2ddl.auto", "");
hibernateProperties.setProperty(
"hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect");
return hibernateProperties;
}
}
Here is the my util class where sessionFactory is #AutoWired
public class AppHibernateUtil {
private static final AppHibernateUtil instance = new AppHibernateUtil();
#Autowired
private SessionFactory sessionFactory;
public static Session getSession() {
return getInstance().sessionFactory.openSession();
}
private static AppHibernateUtil getInstance() {
return instance;
}
}
Here's my attempted usage of a session
public static String getRoles() {
System.out.println("Custom: getRoles() called");
List<RoleEntity> roles = new ArrayList<>();
try(Session session = AppHibernateUtil.getSession()){
roles = session.createQuery("from RoleEntity").list();
}
return gson.toJson(roles.size());
}
public static void main(String args[]) {
System.out.println(getRoles());
}
The null exception is thrown here
return getInstance().sessionFactory.openSession();
This line never gets outputted at the console
System.out.println("Session factory called!");
If I ignore the AppHibernateUtil class by creating a test class which injects (or not) the sessionFactory. I get the same NPE
#Component
public class TestController {
private static Gson gson = new Gson();
#Autowired
private static SessionFactory sessionFactory;
public static String getRoles() {
System.out.println("Custom: getRoles() called");
List<RoleEntity> roles = new ArrayList<>();
try(Session session = sessionFactory.getCurrentSession()){
roles = session.createQuery("from RoleEntity").list();
}
return gson.toJson(roles.size());
}
public static void main(String args[]) {
System.out.println(getRoles());
}
}
Problem is not in your hibernate configuration, but in your dependency injection.
You are creating manually singleton of AppHibernateUtil (you are calling new AppHibernateUtil()), let Spring do its job and annotate AppHibernateUtil with #Component (default scope of component is Singleton), then inject it into you class, where is your session needed.
My guess is that the NPE is being thrown because the sessionFactory in the getSession() method is null.
This means that Spring is not injecting an instance of SessionFactory.
That may be because you've chosen to implemented the AppHibernateUtil as a singleton. I won't disgress into a discussion about that, except that's it's relevant to point out that Spring is based on dependency injection and using singletons goes against that approach.
If you want to keep using a singleton, you may have success with additional annotations on the AppHibernateUtil class:
#Configuration
#ComponentScan("com.your.package.HibernateConfig")
public class AppHibernateUtil {
...
}
However, as described in the docs, it would probably be best to refactor the AppHibernateUtil class so that it was not a singleton:
#Configuration
public class AppHibernateUtil {
private final AppConfig appConfig;
public AppHibernateUtil(AppConfig appConfig) {
this.appConfig = appConfig;
}
}
I have a code that is very similar to this one:
dslContext.transaction(new TransactionalRunnable()
{
#Override
public void run(Configuration arg0) throws Exception
{
dao1.insert(object1);
//Object 1 is inserted in the database
//despite the exception that is being thrown
if(true)
throw new RuntimeException();
dao2.insert(object2)
}
});
This is the code I'm using to create the dsl context and the daos that have been generated with JOOQ.
ComboPooledDataSource comboPooledDataSource = new ComboPooledDataSource();
comboPooledDataSource.setDriverClass(org.postgresql.Driver.class.getName());
comboPooledDataSource.setJdbcUrl("jdbc:postgresql://localhost:5432/database?searchpath=schema");
comboPooledDataSource.setUser("user");
comboPooledDataSource.setPassword("password");
comboPooledDataSource.setMinPoolSize(5);
comboPooledDataSource.setAcquireIncrement(5);
comboPooledDataSource.setMaxPoolSize(25);
Configuration configuration=new DefaultConfiguration().set(comboPooledDataSource).set(
SQLDialect.POSTGRES);
DSLContext dslContext=DSL.using(configuration);
Dao1 dao1=new Dao1(configuration);
Dao2 dao2=new Dao2(configuration);
Why am I getting this behavior?
Your DAOs are configured with a different configuration than your transaction. This means that each DAO runs its code in a new auto-committed transaction, even if you put that logic inside of a TransactionalRunnable.
This would work:
dslContext.transaction(new TransactionalRunnable()
{
#Override
public void run(Configuration arg0) throws Exception
{
new Dao1(arg0).insert(object1);
if(true)
throw new RuntimeException();
new Dao2(arg0).insert(object2)
}
});
Note that [DSLContext.transaction(TransactionalRunnable][1]) does not modify the dslContext and its enclosed Configuration. This means that if your data source is not working e.g. like a JavaEE or Spring TransactionAwareDataSourceProxy, then you must use the argument Configuration of your run() method to run further queries, either by wrapping it with DSL.using(configuration) or by passing it to your daos.
A much simpler option would be to use a data source that is transaction aware (i.e. it binds a transaction to a thread), such that the same thread will always get the same transacted JDBC Connection from the datasource.
I'm letting spring handle the transactions with jOOQ. Here is how:
This is the spring configuration class:
#Configuration
public class SpringConfiguration
{
#Bean
public DataSource dataSource() throws PropertyVetoException
{
comboPooledDataSource.setDriverClass(org.postgresql.Driver.class.getName());
comboPooledDataSource
.setJdbcUrl("jdbc:postgresql://localhost:5432/database?searchpath=schema");
comboPooledDataSource.setUser("databaseuser");
comboPooledDataSource.setPassword("password");
comboPooledDataSource.setMinPoolSize(5);
comboPooledDataSource.setAcquireIncrement(5);
comboPooledDataSource.setMaxPoolSize(25);
return comboPooledDataSource;
}
#Bean
public DataSourceTransactionManager transactionManager() throws PropertyVetoException
{
return new DataSourceTransactionManager(dataSource());
}
#Bean
public TransactionAwareDataSourceProxy transactionAwareDataSource() throws PropertyVetoException
{
return new TransactionAwareDataSourceProxy(dataSource());
}
#Bean
public DataSourceConnectionProvider connectionProvider() throws PropertyVetoException
{
return new DataSourceConnectionProvider(transactionAwareDataSource());
}
#Bean
public org.jooq.Configuration configuration() throws PropertyVetoException
{
return new DefaultConfiguration().set(connectionProvider()).set(transactionProvider()).set(SQLDialect.POSTGRES);
}
#Bean
public TransactionProvider transactionProvider() throws PropertyVetoException
{
return new SpringTransactionProvider(transactionManager());
}
#Bean
public DSLContext dslContext() throws PropertyVetoException
{
return DSL.using(configuration());
}
}
And this is the SpringTransactionProvider:
public class SpringTransactionProvider implements TransactionProvider
{
DataSourceTransactionManager transactionManager;
public SpringTransactionProvider(DataSourceTransactionManager transactionManager)
{
this.transactionManager = transactionManager;
}
#Override
public void begin(TransactionContext ctx)
{
TransactionStatus tx = transactionManager.getTransaction(new DefaultTransactionDefinition(
TransactionDefinition.PROPAGATION_REQUIRED));
ctx.transaction(new SpringTransaction(tx));
}
#Override
public void commit(TransactionContext ctx)
{
transactionManager.commit(((SpringTransaction) ctx.transaction()).tx);
}
#Override
public void rollback(TransactionContext ctx)
{
transactionManager.rollback(((SpringTransaction) ctx.transaction()).tx);
}
class SpringTransaction implements Transaction
{
final TransactionStatus tx;
SpringTransaction(TransactionStatus tx)
{
this.tx = tx;
}
}
}
And finally to get the DSLContext:
ApplicationContext applicationContext = new AnnotationConfigApplicationContext(SpringConfiguration.class);
DSLContext dslContext=applicationContext.getBean(DSLContext.class);
You will need those jars in your classpath to get this to work:
spring-tx.jar, spring-aop.jar, spring-expression.jar, spring-core.jar, spring-beans.jar, spring-jdbc.jar and spring-context.jar :)
I'm trying to Autowire service inside java class which is extended from TimerTask. This Returning null value while trying to return service in java class. This is the class in which I'm trying to Autowire service:
#Component
public class Task extends TimerTask
{
#Autowired
FileDetailsService fileDetailsService;
int count = 1;
#Override
public void run()
{
fileDetailsService.updateProcessingStatus(fileAudit);
}
Configuration classes: There is no web.xml.....I have configured in java using spring 4
//DataConfig.java
#Configuration
#MapperScan("com.fileC.mapper")
public class DataConfig {
#Bean
public DataSource dataSource() {
SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
dataSource.setDriverClass(oracle.jdbc.driver.OracleDriver.class);
dataSource.setUsername("username");
dataSource.setUrl("jdbc***thin**sample **url");
dataSource.setPassword("****");
return dataSource;
}
#Bean
public DataSourceTransactionManager transactionManager() {
return new DataSourceTransactionManager(dataSource());
}
#Bean
public SqlSessionFactoryBean sqlSessionFactory() throws Exception {
SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
sessionFactory.setDataSource(dataSource());
sessionFactory.setTypeAliasesPackage("com.fileC.model");
return sessionFactory;
}
//ApplConfig.java
#Configuration
#ComponentScan(basePackages="com.filec")
public class ApplConfig {
#Bean
public CommonsMultipartResolver multipartResolver(){
CommonsMultipartResolver commonsMultipartResolver = new CommonsMultipartResolver();
commonsMultipartResolver.setDefaultEncoding("utf-8");
commonsMultipartResolver.setMaxUploadSize(50000000);
return commonsMultipartResolver;
}
}
I'm using Spring4, java1.8, ibatis, SQL database.
Here is the service class,
#Service("fileDetailsService")
#Transactional
public class FileDetailsServiceImpl implements FileDetailsService{
private static Logger logger = LoggerFactory.getLogger(FileDetailsServiceImpl.class);
#Autowired
FileDetailsMapper fileDetailsMapper;
#Override
public void insertFileInfo(Details details){
fileDetailsMapper.insertDetails(details);
}
Here is the exception details,
fileAuditMapper>>>>null
Exception in thread "Timer-9" java.lang.NullPointerException at com.filecompare.service.Task.run(Task.java:117)
at java.util.TimerThread.mainLoop(Timer.java:555)
at java.util.TimerThread.run(Timer.java:505)
Please, let me know if I need to add something in config.
I am using scheduled task to update my database like this:
public interface UserRatingManager {
public void updateAllUsers();
}
#Service
public class DefaultUserRatingManager implements UserRatingManager {
#Autowired
UserRatingDAO userRatingDAO;
#Override
#Transactional("txName")
public void updateAllUsers() {
List<String> userIds = userRatingDAO.getAllUserIds();
for (String userId : userIds) {
updateUserRating(userId);
}
}
}
public interface UserRatingDAO extends GenericDAO<UserRating, String> {
public void deleteAll();
public List<String> getAllUserIds();
}
#Repository
public class HibernateUserRatingDAO extends BaseDAO<UserRating, String> implements UserRatingDAO {
#Override
public List<String> getAllUserIds() {
List<String> result = new ArrayList<String>();
Query q1 = getSession().createQuery("Select userId from UserRating");
}
}
I configured the persistence like this:
#Configuration
#ComponentScan({ "com.estartup" })
#PropertySource("classpath:jdbc.properties")
#EnableTransactionManagement
#EnableScheduling
public class PersistenceConfig {
#Autowired
Environment env;
#Scheduled(fixedRate = 5000)
public void run() {
userRatingManager().updateAllUsers();
}
#Bean
public DataSource dataSource() {
DriverManagerDataSource driverManagerDataSource = new DriverManagerDataSource(env.getProperty("connection.url"), env.getProperty("connection.username"), env.getProperty("connection.password"));
driverManagerDataSource.setDriverClassName("com.mysql.jdbc.Driver");
return driverManagerDataSource;
}
public PersistenceConfig() {
super();
}
#Bean
public UserRatingUpdate userRatingUpdate() {
return new UserRatingUpdate();
}
#Bean
public UserRatingManager userRatingManager() {
return new DefaultUserRatingManager();
}
#Bean
public LocalSessionFactoryBean runnableSessionFactory() {
LocalSessionFactoryBean factoryBean = null;
try {
factoryBean = createBaseSessionFactory();
} catch (Exception e) {
e.printStackTrace();
}
return factoryBean;
}
private LocalSessionFactoryBean createBaseSessionFactory() throws IOException {
LocalSessionFactoryBean factoryBean;
factoryBean = new LocalSessionFactoryBean();
Properties pp = new Properties();
pp.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
pp.setProperty("hibernate.max_fetch_depth", "3");
pp.setProperty("hibernate.show_sql", "false");
factoryBean.setDataSource(dataSource());
factoryBean.setPackagesToScan(new String[] { "com.estartup.*" });
factoryBean.setHibernateProperties(pp);
factoryBean.afterPropertiesSet();
return factoryBean;
}
#Bean(name = "txName")
public HibernateTransactionManager runnableTransactionManager() {
HibernateTransactionManager htm = new HibernateTransactionManager(runnableSessionFactory().getObject());
return htm;
}
}
However, when I get to:
Query q1 = getSession().createQuery("Select userId from UserRating");
in the above HibernateUserRatingDAO I get an exception:
org.hibernate.HibernateException: createQuery is not valid without active transaction
at org.hibernate.context.internal.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:352)
at com.sun.proxy.$Proxy63.createQuery(Unknown Source)
at com.estartup.dao.impl.HibernateUserRatingDAO.getAllUserIds(HibernateUserRatingDAO.java:36)
How can I configure to include my scheduled tasks in transactions ?
EDITED:
Here is the code for BaseDAO
#Repository
public class BaseDAO<T, ID extends Serializable> extends GenericDAOImpl<T, ID> {
private static final Logger logger = LoggerFactory.getLogger(BaseDAO.class);
#Autowired
#Override
public void setSessionFactory(SessionFactory sessionFactory) {
super.setSessionFactory(sessionFactory);
}
public void setTopAndForUpdate(int top, Query query){
query.setLockOptions(LockOptions.UPGRADE);
query.setFirstResult(0);
query.setMaxResults(top);
}
EDITED
Enabling Spring transaction prints the following log:
DEBUG [pool-1-thread-1] org.springframework.transaction.annotation.AnnotationTransactionAttributeSource - Adding transactional method 'updateAllUsers' with attribute: PROPAGATION_REQUIRED,ISOLATION_DEFAULT; 'txName'
What is happening in this case is that since you are using userRatingManager() inside the configuration (where the actual scheduled method exists), the proxy that Spring creates to handle the transaction management for UserRatingUpdate is not being used.
I propose you do the following:
public interface WhateverService {
void executeScheduled();
}
#Service
public class WhateverServiceImpl {
private final UserRatingManager userRatingManager;
#Autowired
public WhateverServiceImpl(UserRatingManager userRatingManager) {
this.userRatingManager = userRatingManager;
}
#Scheduled(fixedRate = 5000)
public void executeScheduled() {
userRatingManager.updateAllUsers()
}
}
Also change your transaction manager configuration code to:
#Bean(name = "txName")
#Autowired
public HibernateTransactionManager runnableTransactionManager(SessionFactory sessionFactory) {
HibernateTransactionManager htm = new HibernateTransactionManager();
htm.setSessionFactory(sessionFactory);
return htm;
}
and remove factoryBean.afterPropertiesSet(); from createBaseSessionFactory
As I already mentioned, I used your code and created a small sample that works for me. Judging by the classes used, I assumed you are using Hibernate Generic DAO Framework. It's a standalone sample, the main() class is Main. Running it you can see the transactional related DEBUG messages in logs that show when a transaction is initiated and committed. You can compare my settings, jars versions used with what you have and see if anything stands out.
Also, as I already suggested you might want to look in the logs to see if proper transactional behavior is being used and compare that with the logs my sample creates.
I tried to replicate your problem so I integrated it in my Hibernate examples on GitHub:
You can run my CompanySchedulerTest and see it's working so this is what I did to run it:
I made sure the application context is aware of our scheduler
<task:annotation-driven/>
The scheduler is defined in its own bean:
#Service
public class CompanyScheduler implements DisposableBean {
private static final Logger LOG = LoggerFactory.getLogger(CompanyScheduler.class);
#Autowired
private CompanyManager companyManager;
private volatile boolean enabled = true;
#Override
public void destroy() throws Exception {
enabled = false;
}
#Scheduled(fixedRate = 100)
public void run() {
if (enabled) {
LOG.info("Run scheduler");
companyManager.updateAllUsers();
}
}
}
My JPA/Hibernate configs are in applicationContext-test.xml and they are configured for JPA according to the Spring framework indications, so you might want to double check your Hibernate settings as well.