Does the @Embeddable
for @ManyToMany
relations and additional columns, works with String
?
I do not use @Generated Value for @Id
Because my Entity ApplikationUser
@Id
@Column(length = 128)
private String applikationUserId;
by business logic has always an Id
Here my code:
@EmbeddedId
private ApplikationUserPopupMessageId applikationUserPopupMessageId;
@ManyToOne(fetch = FetchType.EAGER)
@MapsId("applikationUserId")
private ApplikationUser applikationUser;
@ManyToOne(fetch = FetchType.EAGER)
@MapsId("popupMessageId")
private PopupMessage popupMessage;
@Column(name = "gelesen")
private boolean gelesen = false;
@Embeddable
public class ApplikationUserPopupMessageId implements Serializable {
@Column(name = "applikation_user_id")
private String applikationUserId;
@Column(name = "popup_message_id")
private Long popupMessageId;
@Entity
@Table
public class PopupMessage {
@Id
@GeneratedValue
@Column(length = 128)
private Long messageId;
private String title;
private String message;
@OneToMany(
mappedBy = "applikationUser",
cascade = CascadeType.ALL,
orphanRemoval = true
)
private List<ApplikationUserPopupMessage> applikationUserPopupMessages = new ArrayList<>();
@Entity
public class ApplikationUser implements UserDetails {
/**
*
*/
private static final long serialVersionUID = -5517804528054972083L;
@Id
@Column(length = 128)
private String applikationUserId;
@Column
private String password;
@ManyToOne
@JoinColumn(name = "idRole")
private Role role;
private boolean enabled = true;
@OneToMany(
mappedBy = "popupMessage",
cascade = CascadeType.ALL,
orphanRemoval = true
)
private List<ApplikationUserPopupMessage> applikationUserPopupMessages = new ArrayList<>();
EDIT - 23.11.2020
Regards the lack of interest, its seems to be possible to us @Embeddable
with String
?
Instantiate applikationUserPopupMessageId:
@Entity
public class ApplikationUserPopupMessage {
@EmbeddedId
private ApplikationUserPopupMessageId applikationUserPopupMessageId = new ApplikationUserPopupMessageId();
}
That's known issue
Just put getters and setters for the according properties in your @Embeddable
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With