Skip to content

Hibernate StatelessSession Transaction issue #35602

@hantsy

Description

@hantsy

Environment:

Description

In Spring 7, Hibernate StatelessSession participate into the transaction which fills the blank when integrating Jakarta Data/Hibernate and Spring.

To test it, I have updated my Jakarta Data example to use Spring 7/Hibernate 7.1 stack.

@jakarta.data.repository.Repository
public interface JakartaDataPostRepository {

    @Transactional
    @Delete
    int deleteAll();

    @Transactional
    @Save
    Post save(Post post);

    @Find
    List<Post> findAll();

    @Query("from Post p where p.title like :s and p.status=:status")
    List<Post> findByKeyword(@Param("s") String s, @Param("status") Status status, Limit limit);

    @Find
    Optional<Post> findById(UUID id);
}

When compiling the project, it generated the implelementation class like this.

@Component
public class JakartaDataPostRepository_ implements JakartaDataPostRepository {

	
	/**
	 * @see #findByKeyword(String,Status,Limit)
	 **/
	static final String FIND_BY_KEYWORD_String_Status = "from Post p where p.title like :s and p.status=:status";

	
	protected ObjectProvider<StatelessSession> session;
	
	public JakartaDataPostRepository_(ObjectProvider<StatelessSession> session) {
		this.session = session;
	}
	
	public StatelessSession session() {
		return session.getObject();
	}
	
	@Override
	public Post save(Post post) {
        // ...

When running the tests, I got the exception:

Caused by: org.hibernate.HibernateException: Could not obtain 
transaction-synchronized Session for current thread

As normal, I have configured Hibernate LocalSessionFactoryBean and HibernateTransactionManager in the JakartaDataConfig.

Metadata

Metadata

Assignees

Labels

in: dataIssues in data modules (jdbc, orm, oxm, tx)status: invalidAn issue that we don't feel is valid

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions