blaze-persistence icon indicating copy to clipboard operation
blaze-persistence copied to clipboard

One-to-one mapping issue with inverse and MapsId

Open beikov opened this issue 2 years ago • 0 comments

@Entity
public class LdapGroupConfiguration {
@Id
@Column(name = "server_id")
private Long id;

@OneToOne
@MapsId
@JoinColumn(name = "server_id")
private LdapServerConfiguration serverConfiguration;
}

@Entity
public class LdapServerConfiguration implements Serializable {
@Id
private Long id;

@OneToOne(cascade = CascadeType.REMOVE, mappedBy = "serverConfiguration")
private LdapGroupConfiguration groupConfiguration;
}

@CreatableEntityView
@EntityView(LdapServerConfiguration.class)
public interface LdapServerConfigurationCreateView extends LdapServerConfigurationIdView {
@UpdatableMapping(cascade = CascadeType.DELETE)
LdapGroupConfigurationIdView getGroupConfiguration();

void setGroupConfiguration(LdapGroupConfigurationIdView groupConfiguration);
}

@UpdatableEntityView
@EntityView(LdapServerConfiguration.class)
public interface LdapServerConfigurationCreateView extends LdapServerConfigurationIdView {

@InverseMapping(removeStrategy = REMOVE)
@UpdatableMapping(cascade = CascadeType.DELETE)
LdapGroupConfigurationIdView getGroupConfiguration();

void setGroupConfiguration(LdapGroupConfigurationIdView groupConfiguration);
}

Play around with and without @JoinColumn, @InverseMapping. The join column shouldn't be necessary. The @InverseMapping is reported to be wrong when @JoinColumn is present, although it is never wrong.

beikov avatar Jun 13 '23 14:06 beikov