I am using Spring , JPA, Hibernate, Postgresql. I can upload/insert a file to the database. But I got the error when tried to access the file.
EVERE: Servle
Since you have defined your Spring transactions via @Transactional
, you are by default running inside of an auto-commit transaction. As per this other thread, you need to create a second session factory which runs in autocommit = false
to retrieve the file.
Additionally, the DAO for the retrieval should be annotated with @Qualifier
so that it knows which session factory to use. Example:
@Autowired
public MyDAOImpl(@Qualifier("someSessionFactory") SessionFactory sessionFactory) {
setSessionFactory(sessionFactory);
}