@TenantDiscriminatorColumn在@datajpatest中不起作用

发布于 2025-01-27 12:21:13 字数 1381 浏览 3 评论 0原文

我正在尝试使用“ instance_id”作为表ML_Cachelock的租户歧视列。并尝试通过@datajpatest进行测试,但最终发现该列无法预先设置,并且插入语句不会自动包含此列。
你能帮忙吗?
以下是相关代码。

@Entity
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Table(name = "ML_CACHE_LOCK")
@Multitenant(MultitenantType.SINGLE_TABLE)
@TenantDiscriminatorColumn(name = "INSTANCE_ID")

public class MLCacheLock implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @Column(name = "REQUEST_ID", nullable = false)
    private Long requestID;

    @Column(name = "LOCK_STATUS", nullable = false)
    private long lockStatus;

}

import org.springframework.data.jpa.repository.JpaRepository;

import com.sap.cloud.platform.mobile.services.service.offline.persistence.domain.MLCacheLock;

public interface MLCacheLockRepository extends JpaRepository<MLCacheLock, Long> {

}

测试代码:

@DataJpaTest
@AutoConfigureTestDatabase
@RunWith(SpringRunner.class)
public class RepositoryIT {

@Autowired
private MLCacheLockRepository cacheLockRepository;


@Test
public void testFindAll() {
    cacheLockRepository.saveAll(Arrays.asList(new MLCacheLock(1111L, 1L), new MLCacheLock(1112L, 2L)));

    cacheLockRepository.flush();

    List<MLCacheLock> res = cacheLockRepository.findAll();
    assertTrue(2 == res.size());
  }
}

最后,它始终报告:Insert操作中缺少Instance_ID。

I'm trying to use "INSTANCE_ID" as the tenant discriminator column for table ML_CACHELOCK. and try to test it via @DataJpaTest, but finally find that this column can't be set in advance and the insert statement is not automatically including this column.
Could you help?
Below is the related code.

@Entity
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Table(name = "ML_CACHE_LOCK")
@Multitenant(MultitenantType.SINGLE_TABLE)
@TenantDiscriminatorColumn(name = "INSTANCE_ID")

public class MLCacheLock implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @Column(name = "REQUEST_ID", nullable = false)
    private Long requestID;

    @Column(name = "LOCK_STATUS", nullable = false)
    private long lockStatus;

}

import org.springframework.data.jpa.repository.JpaRepository;

import com.sap.cloud.platform.mobile.services.service.offline.persistence.domain.MLCacheLock;

public interface MLCacheLockRepository extends JpaRepository<MLCacheLock, Long> {

}

The test code:

@DataJpaTest
@AutoConfigureTestDatabase
@RunWith(SpringRunner.class)
public class RepositoryIT {

@Autowired
private MLCacheLockRepository cacheLockRepository;


@Test
public void testFindAll() {
    cacheLockRepository.saveAll(Arrays.asList(new MLCacheLock(1111L, 1L), new MLCacheLock(1112L, 2L)));

    cacheLockRepository.flush();

    List<MLCacheLock> res = cacheLockRepository.findAll();
    assertTrue(2 == res.size());
  }
}

Finally, it always reports that : INSTANCE_ID is missing in the insert operation.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文