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

问题描述 投票:0回答:1

我具有自定义库-实体的auditBase。有带有@ MappedSuperclass,@ EntityListener和@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"
    )...

在当前项目中,有一个名为“ area”的实体。这个实体是@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;...

另外两个实体扩展了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;...

与PlaceEntity相关的最后一个实体:

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

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

我有一个简单的查询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);

使用后,我有这样的异常:

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

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

java hibernate jpa inheritance entity
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.