我是新来的,我希望你能帮助我们.
我有一个懒惰的提取类型的问题.
我不想取得所有关系,只要我需要.当我使用CommandLineRunner.run方法时,它没关系,它正在提取Lazily,但如果我从中调用该方法RestController,它总是热切地提取,但我不想要那样.
我试过了:
最后,我正在使用SpringUserDetailsService的Spring安全性.当我登录时,它返回User对象.如果@Transactional注释是在ServiceImpl类上,它正在急切地获取,但是如果我删除了那个注释,那么它就是Lazily,但这只能在登录时使用.
你有什么主意吗?
库:
import hu.pte.clms.model.domain.User;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Repository;
@Repository
public interface UserRepository extends JpaRepository<User, Long>, JpaSpecificationExecutor{
}
Run Code Online (Sandbox Code Playgroud)
ServiceImpl:
import hu.pte.clms.model.domain.User;
import hu.pte.clms.repository.UserRepository;
import hu.pte.clms.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Service
@Transactional …Run Code Online (Sandbox Code Playgroud)