Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

org.hibernate.PropertyAccessException: Could not set field value [STRING] value by reflection for String

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?

like image 777
Wulf Avatar asked Nov 08 '20 20:11

Wulf


2 Answers

Instantiate applikationUserPopupMessageId:

@Entity
public class ApplikationUserPopupMessage {
  @EmbeddedId
  private ApplikationUserPopupMessageId applikationUserPopupMessageId = new ApplikationUserPopupMessageId();
}

That's known issue

like image 64
Qwer Izuken Avatar answered Nov 06 '22 00:11

Qwer Izuken


Just put getters and setters for the according properties in your @Embeddable.

like image 35
angrybobcat Avatar answered Nov 06 '22 02:11

angrybobcat