- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有实体 User
和 Conversation
与它们之间的关系 @ManyToMany
:
@Entity
@Table(name="USER")
public class User {
...
...
@ManyToMany
@JoinTable(name="USER_CONVERSATION",
joinColumns = @JoinColumn(name = "user_id"),
inverseJoinColumns = @JoinColumn(name = "conversation_id"))
Set<Conversation> conversations = new HashSet<>();
...
...
}
@Entity
@Table(name="CONVERSATION")
public class Conversation {
...
...
@ManyToMany(mappedBy = "conversations", cascade = {CascadeType.PERSIST, CascadeType.MERGE})
Set<User> users = new HashSet<>();
...
...
}
我想接收具有给定用户列表的所有对话。我尝试过这样的事情:
public interface ConversationRepository extends JpaRepository<Conversation, Long> {
List<Conversation> findAllConversationsByUsers(List<User> users);
但我收到一条错误消息:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'conversationRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract java.util.List pl.teamvi.project.repositories.ConversationRepository.findAllConversationsByUsers(java.util.List)! Operator SIMPLE_PROPERTY on users requires a scalar argument, found interface java.util.List in method public abstract java.util.List pl.teamvi.project.repositories.ConversationRepository.findAllConversationsByUsers(java.util.List).
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1796) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:207) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1114) ~[spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.data.repository.support.Repositories.cacheRepositoryFactory(Repositories.java:99) ~[spring-data-commons-2.2.3.RELEASE.jar:2.2.3.RELEASE]
at org.springframework.data.repository.support.Repositories.populateRepositoryFactoryInformation(Repositories.java:92) ~[spring-data-commons-2.2.3.RELEASE.jar:2.2.3.RELEASE]
at org.springframework.data.repository.support.Repositories.<init>(Repositories.java:85) ~[spring-data-commons-2.2.3.RELEASE.jar:2.2.3.RELEASE]
at org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration.repositories(RepositoryRestMvcConfiguration.java:212) ~[spring-data-rest-webmvc-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration$$EnhancerBySpringCGLIB$$f3b0aabb.CGLIB$repositories$51(<generated>) ~[spring-data-rest-webmvc-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration$$EnhancerBySpringCGLIB$$f3b0aabb$$FastClassBySpringCGLIB$$4b18e8f9.invoke(<generated>) ~[spring-data-rest-webmvc-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:363) ~[spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration$$EnhancerBySpringCGLIB$$f3b0aabb.repositories(<generated>) ~[spring-data-rest-webmvc-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_201]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_201]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_201]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_201]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
... 142 common frames omitted
Caused by: java.lang.IllegalArgumentException: Failed to create query for method public abstract java.util.List pl.teamvi.project.repositories.ConversationRepository.findAllConversationsByUsers(java.util.List)! Operator SIMPLE_PROPERTY on users requires a scalar argument, found interface java.util.List in method public abstract java.util.List pl.teamvi.project.repositories.ConversationRepository.findAllConversationsByUsers(java.util.List).
at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.<init>(PartTreeJpaQuery.java:102) ~[spring-data-jpa-2.2.3.RELEASE.jar:2.2.3.RELEASE]
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:106) ~[spring-data-jpa-2.2.3.RELEASE.jar:2.2.3.RELEASE]
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:211) ~[spring-data-jpa-2.2.3.RELEASE.jar:2.2.3.RELEASE]
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:79) ~[spring-data-jpa-2.2.3.RELEASE.jar:2.2.3.RELEASE]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lookupQuery(RepositoryFactorySupport.java:574) ~[spring-data-commons-2.2.3.RELEASE.jar:2.2.3.RELEASE]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lambda$mapMethodsToQuery$1(RepositoryFactorySupport.java:567) ~[spring-data-commons-2.2.3.RELEASE.jar:2.2.3.RELEASE]
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) ~[na:1.8.0_201]
at java.util.Iterator.forEachRemaining(Iterator.java:116) ~[na:1.8.0_201]
at java.util.Collections$UnmodifiableCollection$1.forEachRemaining(Collections.java:1049) ~[na:1.8.0_201]
at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801) ~[na:1.8.0_201]
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) ~[na:1.8.0_201]
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471) ~[na:1.8.0_201]
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708) ~[na:1.8.0_201]
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:1.8.0_201]
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499) ~[na:1.8.0_201]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.mapMethodsToQuery(RepositoryFactorySupport.java:569) ~[spring-data-commons-2.2.3.RELEASE.jar:2.2.3.RELEASE]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lambda$new$0(RepositoryFactorySupport.java:559) ~[spring-data-commons-2.2.3.RELEASE.jar:2.2.3.RELEASE]
at java.util.Optional.map(Optional.java:215) ~[na:1.8.0_201]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:559) ~[spring-data-commons-2.2.3.RELEASE.jar:2.2.3.RELEASE]
at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:332) ~[spring-data-commons-2.2.3.RELEASE.jar:2.2.3.RELEASE]
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.lambda$afterPropertiesSet$5(RepositoryFactoryBeanSupport.java:297) ~[spring-data-commons-2.2.3.RELEASE.jar:2.2.3.RELEASE]
at org.springframework.data.util.Lazy.getNullable(Lazy.java:212) ~[spring-data-commons-2.2.3.RELEASE.jar:2.2.3.RELEASE]
at org.springframework.data.util.Lazy.get(Lazy.java:94) ~[spring-data-commons-2.2.3.RELEASE.jar:2.2.3.RELEASE]
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:300) ~[spring-data-commons-2.2.3.RELEASE.jar:2.2.3.RELEASE]
at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:121) ~[spring-data-jpa-2.2.3.RELEASE.jar:2.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1855) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1792) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
... 163 common frames omitted
Caused by: java.lang.IllegalStateException: Operator SIMPLE_PROPERTY on users requires a scalar argument, found interface java.util.List in method public abstract java.util.List pl.teamvi.project.repositories.ConversationRepository.findAllConversationsByUsers(java.util.List).
at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.throwExceptionOnArgumentMismatch(PartTreeJpaQuery.java:177) ~[spring-data-jpa-2.2.3.RELEASE.jar:2.2.3.RELEASE]
at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.validate(PartTreeJpaQuery.java:153) ~[spring-data-jpa-2.2.3.RELEASE.jar:2.2.3.RELEASE]
at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.<init>(PartTreeJpaQuery.java:96) ~[spring-data-jpa-2.2.3.RELEASE.jar:2.2.3.RELEASE]
... 189 common frames omitted
有没有办法在不使用 @Query
注释的情况下编写此查询?
如果我将方法更改为:
List<Conversation> findAllConversationsByUsers(User users);
我没有任何错误? Users
是 Set
,而不是单个元素,那么该查询在做什么?
最佳答案
我遇到了同样的问题,为了解决它,我在方法的末尾添加了“In”后缀。比如:
List<Conversation> findAllConversationsByUsersIn(List<User> users);
关于java - Spring Data JPA 中关系@ManyToMany 的查询方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59518775/
经过大量搜索但没有成功后,我决定在这里提出我的问题,所以我将首先举一个例子来说明问题。 我有 4 个类(class) A - B - C - D我在 A 和 B 之间有一个名为 A_B 的多对多关系(
该应用程序允许用户选择某些关键字(我们监控 TwitterStream) 每个关键字都包含包含其关键字的推文 ID 列表。 public class Keyword extends Model { @
我有 2 个实体:User 和 UsersList。 @Entity @Table(name = "USERS") public class User { @Id @Generated
嘿,我有一个关于人际关系的问题。 我希望用户有友谊。所以一个用户可以成为另一个用户的 friend 。我假设我需要通过 Friendship 表使用 ManyToManyField。但我无法让它工作。
我需要让帖子接受我需要的尽可能多的语言,所以我有两个模型 post和 language在后模型中: public function languages(){ return $this->bel
在我的一个模型中,我有一个属于多条配置的类别字段。 我想知道如何在模板中获得以下输出。 第 1 类、第 2 类、第 3 类和第 4 类 所以基本上用逗号分隔每个类别,除了最后一个用“和”替换 最佳答案
我有一个用于 User 和 House 的多对多表,称为 user_house。我不想只添加两列:user_id 和 house_id,而是添加 3 列:例如,action、created_at、up
我正在做一个食品卡车 API,只是为了学习 spring-boot。在做的过程中,遇到了关于注释 @Manytomany 如何工作的问题。 因为这个项目只是为了学习我想使用Google CLoud F
我有一个ManyToMany链接和一个链接三个对象的外键。 [A]>-----[C] A 可以属于多个 B,反之亦然。但是,A 只能属于具有同一父对象 C 的 B 对象。 我正在尝试在模型的 clea
如果我有两个模型与直通模型具有多对多关系,我如何从该“直通”表中获取数据。 class Bike(models.Model): nickname = models.CharField(max_l
我已经处理我的用户 - 角色 - 映射问题很长一段时间了,但我目前陷入这个问题: 调用 init 方法失败;嵌套异常是 org.hibernate.AnnotationException:使用 @On
我在坚持方面遇到了问题。我有一个膳食类(class),其中有产品列表。在 Product 类中是一个 Meals 列表——@ManyToMany 关系。 当我尝试保存它时,编译器想要保存每个产品,但随
我正在学习 Spring JPA,我从将对象映射到表开始。我对 OneToOne 和 OneToMany 关系没有任何问题,但我不太明白为什么我无法保留与 ManyToMany 关系相关的对象。我有一
我在 MySQL 中创建了表:role tabel 、 object_label 和 role_object_label (链接表) 我定义了@ManyToMany,但出现异常。我的代码有什么问题?
我有一个包含多个延迟初始化集合的类,其中包括 OneToMany 和 ManyToMany。 ManyToMany 关系是单向的,因此 Expert 类没有 Project 集合。 @OneToMan
我阅读了很多关于这个问题的链接: How to save a django model with a manyToMany Through relationship, AND regular many
我已经实现了一个多图像上传方法,但我想知道使用哪些字段/小部件能够将图像 ID 与表单一起传递。 在填写表单时异步添加图像,并且在提交时,这些图像将被分配给表单正在添加/编辑的对象。我怎样才能传递这个
我遇到了一个尚未解决的问题。 环境: MySQL 5 操作系统 hibernate 4.1 Spring 3.1 Spring Data JPA 我有两个处于多对多关系的实体。为此,我使用带有外键的联
我有两个实体 Post 和 Tags 这个实体有 ManyToMany 的关系,很多帖子有很多标签,很多标签有很多帖子,并且有实体类别我有一个类别的很多帖子,我需要创建 Action 来查找类别的帖子
我的类(class)类(class) @Entity public class Course { @Column @Id private String courseCode;
我是一名优秀的程序员,十分优秀!