JpaSystemException – 无法设置字段值 [auditEntity] 扩展扩展实体

huangapple 未分类评论61阅读模式
英文:

JpaSystemException - cannot set field value [auditEntity] extend extended entity

问题

我有一个自定义的库 - 用于实体的AuditBase。有一个带有@MappedSuperclass,@EntityListener和@RevisionEntity的类。

在当前项目中,有一个名为'area'的实体。这个实体是@MappedSuperclass。

另外还有两个实体扩展自AreaEntity:

最后一个实体与PlaceEntity有关联:

我有一个简单的JpaRepository查询:

在使用它后,我得到了如下异常:

我不知道如何解决这个问题。有人可以帮忙吗?

英文:

i have custom lib - auditBase for entities. there is class with @MappedSuperclass, @EntityListener and @RevisionEntity.

    @RevisionEntity
@MappedSuperclass
@EntityListeners({AuditListener.class})
public class AuditBase {
    @Column(
        name = "client_app_id"
    )
    private String audit_clientAppId;
    @Column(
        name = "company_id"
    )
    private Long audit_companyId;
    @Column(
        name = "insert_date"
    )...

in current project there is Entity for example named 'area'. this entity is @MappedSuperclass

@Entity
@Table(name = "area")
@Inheritance(strategy = InheritanceType.JOINED)
@Getter
@Setter
public class AreaEntity extends AuditBase {

    @Id
    @SequenceGenerator(name = "area", sequenceName = "area", allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "area")
    @Column(name = "area")
    private Long id;

    @Column(name = "json_in_out_afp", columnDefinition = "TEXT")
    private String jsonInOutAfp;

    @Column(name = "afp_external_id", nullable = false, unique = true)
    private Integer afpExternalId;

    @Column(name = "area_status", length = 8, nullable = false)
    private String areaStatus;...

Another two entities extends AreaEntity:

    @Entity
@Table(name = "place")
@Getter
@Setter
public class PlaceEntity extends AreaEntity implements Serializable {

    @Column(name = "kind_of_place", nullable = false, length = 8)
    private String kindOfPlace;

    @Column(name = "measurement", nullable = false)
    private boolean measurement;

    @Column(name = "place_shape_type", nullable = false, length = 8)
    private String placeShapeType;

    @ManyToOne(targetEntity = PlaceSubAreaEntity.class)
    @JoinColumn(name = "fk_place_sub_area", insertable = true, updatable = true)
    private PlaceSubAreaEntity placeSubAreaEntity;...

Last entity with relation to PlaceEntity:

@Entity
@Table(name = "parking_place_sub_area")
@Getter
@Setter
public class PlaceSubAreaEntity extends AreaEntity implements Serializable {

  @OneToMany
  private Set<PlaceEntity> placeEntities = new HashSet<>();...

I have one simple query JpaRepository

@Repository
public interface PlaceRepository extends JpaRepository<PlaceEntity, Long> {

  @Query("select place from PlaceEntity place where place.afpExternalId = :afpExternalId")
  PlaceEntity findByAfpExternalId(@Param("afpExternalId") Integer afpExternalId);

after use it i have exception like this:

org.springframework.orm.jpa.JpaSystemException: Could not set field value [AuditBase(audit_clientAppId=null, audit_companyId=null, audit_insertDate=null, audit_insertedBy=null, audit_updateDate=null, audit_updatedBy=null, audit_updateClientAppId=null, audit_operatorId=null, audit_app=null, audit_appNo=null, audit_appResNo=null, audit_appVer=null, audit_appTraceId=null, audit_appSpanId=null)] value by reflection : [class PlaceEntity.placeSubAreaEntity] setter of PlaceEntity.placeSubAreaEntity; nested exception is org.hibernate.PropertyAccessException: Could not set field value [AuditBase(audit_clientAppId=null, audit_companyId=null, audit_insertDate=null, audit_insertedBy=null, audit_updateDate=null, audit_updatedBy=null, audit_updateClientAppId=null, audit_operatorId=null, audit_app=null, audit_appNo=null, audit_appResNo=null, audit_appVer=null, audit_appTraceId=null, audit_appSpanId=null)] value by reflection : [class PlaceEntity.placeSubAreaEntity] setter of PlaceEntity.placeSubAreaEntity

I have no idea how resolve this problem. Anyone can help?

答案1

得分: 0

在这种情况下,我使用了鉴别器列。它解决了我的问题。

英文:

In this case, i used discriminator column. it solved my problem.

huangapple
  • 本文由 发表于 2020年3月16日 00:20:23
  • 转载请务必保留本文链接:https://java.coder-hub.com/60695008.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定