'@TenantDiscriminatorColumn not work in @DataJpaTest

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.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source