简体   繁体   English

org.hibernate.PropertyAccessException: 无法通过反射为 String 设置字段值 [STRING] 值

[英]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 ? @ManyToMany关系和附加列的@Embeddable是否适用于String I do not use @Generated Value for @Id Because my Entity ApplikationUser我不@Generated Value for @Id使用@Generated Value for @Id因为我的实体ApplikationUser

@Id
@Column(length = 128)
private String applikationUserId;

by business logic has always an Id按业务逻辑始终有一个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 ?编辑 - 23.11.2020关于缺乏兴趣,我们似乎可以使用@EmbeddableString

Instantiate applikationUserPopupMessageId:实例化 applikationUserPopupMessageId:

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

That's known issue这是已知问题

只需在@Embeddable为相应属性放置 getter 和 setter @Embeddable

如果您将访问级别注释为 Field 的实体类是否有帮助

@Entity(access = AccessType.FIELD)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 org.hibernate.PropertyAccessException:无法通过反射getter获取字段值 - org.hibernate.PropertyAccessException: could not get a field value by reflection getter of Hibernate &amp; Spring - org.hibernate.PropertyAccessException: 无法通过反射设置字段值 [1] 值 - Hibernate & Spring - org.hibernate.PropertyAccessException: Could not set field value [1] value by reflection 如何修复org.hibernate.PropertyAccessException:无法通过反射设置器设置字段值 - How to fix org.hibernate.PropertyAccessException: Could not set field value value by reflection setter of 使用ManyToOne获取org.hibernate.PropertyAccessException的JPA Composite键:无法通过反射设置器设置字段值 - JPA Composite key with ManyToOne getting org.hibernate.PropertyAccessException: could not set a field value by reflection setter of org.hibernate.PropertyAccessException:无法使用复合键设置字段值 - org.hibernate.PropertyAccessException: Could not set field value with Composite Key 嵌套的异常是org.hibernate.PropertyAccessException:无法设置字段值 - nested exception is org.hibernate.PropertyAccessException: Could not set field value 错误:-org.hibernate.PropertyAccessException:无法通过反射获取器获取字段值 - Error :- org.hibernate.PropertyAccessException: could not get a field value by reflection getter org.hibernate.PropertyAccessException:空值已分配给布尔类型的属性 - org.hibernate.PropertyAccessException: Null value was assigned to a property of boolean type org.hibernate.PropertyAccessException-如何从数据库中获取空值? - org.hibernate.PropertyAccessException - How to get a null value out of database? org.hibernate.PropertyAccessException:使用CGLIB设置异常的属性值 - org.hibernate.PropertyAccessException: exception setting property value with CGLIB
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM