Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.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
在多租户系统上使用Spring Data Rest和EclipseLink时的QueryException_Spring_Eclipselink_Multi Tenant_Spring Data Rest_Querydsl - Fatal编程技术网

在多租户系统上使用Spring Data Rest和EclipseLink时的QueryException

在多租户系统上使用Spring Data Rest和EclipseLink时的QueryException,spring,eclipselink,multi-tenant,spring-data-rest,querydsl,Spring,Eclipselink,Multi Tenant,Spring Data Rest,Querydsl,我正在使用SpringDataREST和EclipseLink创建一个多租户单表应用程序 但我无法创建一个可以调用自定义QueryParameters的存储库 我的孩子 @Entity @Table(name="kid") @Multitenant public class Kid { @Id private Long id; @Column(name = "tenant_id") private String tenant_id; @Column(name

我正在使用SpringDataREST和EclipseLink创建一个多租户单表应用程序

但我无法创建一个可以调用自定义QueryParameters的存储库

我的孩子

@Entity
@Table(name="kid")
@Multitenant
public class Kid {

   @Id
   private Long id;

   @Column(name = "tenant_id")
   private String tenant_id;

   @Column(name = "mother_id")
   private Long motherId;

   //more attributes, constructor, getter and setter
}
我的孩子

@RepositoryRestResource
public interface KidRepository extends PagingAndSortingRepository<Kid, Long>, QuerydslPredicateExecutor<Kid> {}
当我删除实体上的@Multitenant注释时,一切正常。所以它肯定与日食有关

当我不从QuerydslPredicateExecutor扩展时,它也可以工作。但是我必须自己实现所有的findBy。即使这样,它也会再次破裂。将我的孩子储蓄更改为:

@RepositoryRestResource
public interface KidRepository extends PagingAndSortingRepository<Kid, Long> {
    Collection<Kid> findByMotherId(@Param("motherId") Long motherId);
}
@RepositoryRestResource
公共接口存储库扩展了分页和排序存储库{
集合findByMotherId(@Param(“motherId”)长motherId);
}
当我现在调用localhost/kids/search/findByMotherId?motherId=1时,我得到了与上面相同的异常

我使用本教程设置了带有JPA:的EcpliseLink,这意味着平台TransactionManager、createJpaVendorAdapter和GetVendorProperty将被覆盖。 租户id附带jwt,只要我不使用QuerydslPredicateExecutor,一切都可以正常工作,这对于用例来说是必需的

事实证明,使用了错误的JpaTransactionManager,我们依赖于QueryDSL谓词执行器。我无法确定创建了哪一个断点,但在EclipseLink框架代码中有多个断点,没有一个被击中。这两种方法都是如此,使用QuerydslPredicateExecutor或使用自定义findby方法

我在谷歌上搜索了很多,试图覆盖一些基本的EclipseLink方法,但这些方法都不起作用。我别无选择了


有人知道如何解决这个问题吗?

我正在寻找解决同样问题的方法;最后的帮助是将Spring的
@Transactional
注释添加到存储库或调用此自定义查询的任何位置。(它甚至可以与javax.transactional一起使用。)我们在大多数服务上都有
@transactional
注释,因此问题并不明显,而且它的出现似乎相当偶然


关于在存储库上使用
@Transactional
的更详细解释如下:。

您添加了一个EclipseLink注释,告诉它在每个查询或EntityManager上都需要租户上下文信息,但不支持传入,因为它不是Spring特性。请参见,您将不得不在从EntityManagerFactory创建EntityManager的Spring类中使用属性。有论坛帖子说他们正在使用spring的多租户,你可能想看看。谢谢你的评论。所有设置都与本教程中的一样:租户id是jwt的一部分。只要我不从我的存储库中的QuerydslPredicateExecutor进行扩展,所有东西都可以找到。我会更新我的帖子。
@RepositoryRestResource
public interface KidRepository extends PagingAndSortingRepository<Kid, Long> {
    Collection<Kid> findByMotherId(@Param("motherId") Long motherId);
}