In a micronaut project I have this entity:
@AllArgsConstructor
@Getter
@Setter
@Entity
@Table(name = "product_client_systems")
@DynamicUpdate
public class ProductClientSystem implements Serializable {
@EmbeddedId
private ProductClientSystemId primaryKey;
@ManyToOne(fetch =FetchType.LAZY)
@JoinColumn(name = "client_id")
@MapsId("clientSystemId")
private ClientSystem clientSystem;
@ManyToOne(fetch =FetchType.LAZY)
@JoinColumn(name = "product_id")
@MapsId("articleItemId")
private Product product;
@Column(name = "active" )
private Boolean active = true;
@Column(name = "created_at", updatable = false)
@Temporal(TemporalType.TIMESTAMP)
private Date createdAt = new Date();
This is the id:
@Embeddable
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
public class ProductClientSystemId implements Serializable {
@Column(name = "product_id")
private Long articleItemId;
@Column(name = "client_id")
private Long clientSystemId;
I have created a repo with a custom update so I can update more than one item:
@Repository
public interface ProductClientSystemRepository extends JpaRepository<ProductClientSystem, ProductClientSystemId> {
public List<ProductClientSystem> findByProductInList(List<Product> list);
@Query("update ProductClientSystem set updatedAt=:updatedAt WHERE product in :list")
public void updateUpdatedAtByProductInList( Date updatedAt, List<Product> list);
@Query("update ProductClientSystem o set o.active=:active WHERE o in :list")
public void updateActive(List<ProductClientSystem> list, boolean active);
}
The problem happens when I run a test, the update doesn´t look to update nothing:
@MicronautTest
@TestInstance(TestInstance.Lifecycle.PER_METHOD)
public class RTest {
@Test
void testRandom(){
productClientSystemRepository.updateActive(articleCSNewUpdates,false);
articleCSNewUpdates = productClientSystemRepository.findAll();
assertFalse(articleCSNewUpdates.get(0).getActive()); // HERE IS THE ERROR
}
The most strange thing is that if I run the app and I test it against an endpoint it works. I mean, the error only happens in the test.
Any suggestion?
Regards