vendredi 22 mai 2020

Generated query from memory database is not accurate

I have an entity in containing :

@Entity
@Table(name = "pictures")
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Getter
@Setter
public class PictureEntity {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", insertable = false, updatable = false, nullable = false)
private UUID id;

@Column
private String path;

@Column(name = "thumb_path")
private String thumbPath;

@Column
@Enumerated(EnumType.STRING)
private Status status;

@Column(name = "creation_utc")
@Temporal(TemporalType.TIMESTAMP)
private Date creationTimeUtc;

@Column(name = "creation_local")
@Temporal(TemporalType.TIMESTAMP)
private Date creationTimeLocal;

@ManyToOne
@JoinColumn(name = "project_id", updatable = true, insertable = true)
private ProjectEntity project;

@ManyToOne
@JoinColumn(name = "user_id", updatable = true, insertable = true)
private UserEntity user;

@OneToOne(mappedBy = "picture", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
private ProcessedPictureEntity processedPicture;

public enum Status {
    VALIDATED,
    PROCESSED,
    REJECTED,
    WAITING_VALIDATION
}

}

When I call a save with H2 database, it saves the "project_id" field too. But if I use mysql, the generated query isn't the same, project is not saved (which I think is the correct behavior). I want the test with H2 to crash if updatable/insertable on project_id are false.

How can I correct this ?

Aucun commentaire:

Enregistrer un commentaire