Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Can';是否显示实体所有者的实体?_Java_Spring Security_Jhipster - Fatal编程技术网

Java Can';是否显示实体所有者的实体?

Java Can';是否显示实体所有者的实体?,java,spring-security,jhipster,Java,Spring Security,Jhipster,我试图让jhipster应用程序的用户只访问他创建的实体。这是我的代码: public interface BlogRepository extends JpaRepository<Blog, Long> { @Query("select blog from Blog blog where blog.user.login = ?#{principal.username}") List<Blog> findAllForCurrentUser(); } } 但我的问题是

我试图让jhipster应用程序的用户只访问他创建的实体。这是我的代码:

public interface BlogRepository extends JpaRepository<Blog, Long> {

@Query("select blog from Blog blog where blog.user.login = ?#{principal.username}")
List<Blog> findAllForCurrentUser();
} 
}

但我的问题是,当用户创建一些实体时,没有为他显示任何实体,我不知道为什么?我错过什么了吗?请注意,我的博客实体与用户实体之间存在多对一关系。
正在等待您的帮助…

数据库中的数据是否正确?你能打开sql调试来显示发送到数据库的实际sql吗?是的,数据被插入到数据库中,但发现问题后我无法解决:事实上,我有一个属性user是实体的所有者,这个属性应该自动对用户进行身份验证,但我不能这样做
@Timed
public List<Blog> getAll() {
 log.debug("REST request to get all Blogs for current user");
 return blogRepository.findAllForCurrentUser();
 }



<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<version>${spring-security.version}</version>
<scope>test</scope>
@Autowired
WebApplicationContext context;

@Inject
UserRepository userRepository;

 @Test

  @Transactional

  public void getAllBlogs() throws Exception {
restBlogMockMvc = MockMvcBuilders.webAppContextSetup(context).apply(springSecurity()).build();

 // Initialize the database
 blog.setUser(userRepository.findOneByLogin("user").get());
 blogRepository.saveAndFlush(blog);

 // Get all the blogs
restBlogMockMvc.perform(get("/api/blogs").with(user("user")))
    .andExpect(status().isOk())
    .andExpect(content().contentType(MediaType.APPLICATION_JSON))
    .andExpect(jsonPath("$.[*].id").value(hasItem(blog.getId().intValue())))
    .andExpect(jsonPath("$.[*].name").value(hasItem(DEFAULT_NAME.toString())))
    .andExpect(jsonPath("$.[*].handle").value(hasItem(DEFAULT_HANDLE.toString())));