我想使用来自rabbitmq的消息。作为此过程的一部分,我从spring-data存储库中读取实体。当我尝试访问该实体的延迟初始化字段时,我得到:
org.hibernate.LazyInitializationException: could not initialize proxy - no Session
这是我的听众:
@RabbitListener(bindings = {
@QueueBinding(
value = @Queue(value = EVENT_QUEUE, durable = "true"),
exchange = @Exchange(value = EventConstants.EVENT_EXCHANGE_NAME, type = EventConstants.EVENT_EXCHANGE_TYPE)
})
@Transactional
protected void handleSubscriptionCreated(Subscription subscription) {
// just sample code
repository.find(subscription.getId())).getAccount();
}
我尝试通过强制执行事务来创建会话,但这不起作用。