Spring Boot Quartz - LazyInitializationException
Date : March 29 2020, 07:55 AM
will help you I am trying to schedule a job using Quartz in Spring boot. below are the code which I am using below are my configurations... , I was able to fix the issue by changing SchedulerFactoryBean @Autowired
HCJobFactory jobFactory;
@Autowired
DataSource dataSource;
@Autowired
ApplicationContext applicationContext;
@Override
public void afterPropertiesSet() throws Exception
{
setJobFactory( jobFactory.getJobFactory() );
setApplicationContext(applicationContext);
setDataSource( dataSource );
//setTransactionManager( transactionManager );
super.afterPropertiesSet();
}
|
Transaction inside transaction support? (multi database) in Spring boot
Date : March 29 2020, 07:55 AM
Does that help @Transaction annotation has an attribute rollbackFor (@Transaction(value = "DB1", rollbackFor = SqlException.class) for example) that may cover your needs. However, there is only one transaction will be actually used in your code, because B is invoked not via Spring proxy but via inner call (this.B()). To execute method inside a separate transaction method must be invoked via Spring proxy - someService.B(), not this.B().
|
How spring transaction works in this example and how to resolve LazyInitializationException?
Date : March 29 2020, 07:55 AM
help you fix your problem I am getting org.hibernate.LazyInitializationException exception. What I know is, the issue is caused because I have fetched profile object in user entity lazily and before proxy object gets initialized the session is closed. , Is the session closed after executing findAll() method?
|
LazyInitializationException in spite of Spring transaction?
Date : March 29 2020, 07:55 AM
|
LazyInitializationException Spring Boot
Date : March 29 2020, 07:55 AM
To fix the issue you can do Because the FetchType of Brand is lazy, it will not automatically be loaded into the session with call to fetchAll(). To have it automatically load into the session, you need to: Change @ManyToOne(cascade=CascadeType.ALL, fetch = FetchType.LAZY)
@JoinColumn(name="brand_id", referencedColumnName="id")
private Brand brand;
@ManyToOne(cascade=CascadeType.ALL, fetch = FetchType.EAGER)
@ManyToOne(cascade=CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name="brand_id", referencedColumnName="id")
private Brand brand;
@Component
public CarService implements ICarService {
@Autowired
CarRepository carRepository;
@Transactional
public void printAllCars() {
for (Car c : carRepository.findAll()) {
System.out.println(c.toString());
}
}
}
|