@TenantDiscriminatorColumn在@datajpatest中不起作用
我正在尝试使用“ 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论