blaze-persistence
blaze-persistence copied to clipboard
One-to-one mapping issue with inverse and MapsId
@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.