JpaSystemException - не может установить значение поля [auditEntity]. - PullRequest
0 голосов
/ 15 марта 2020

У меня есть пользовательский lib - 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"
    )...

, в текущем проекте есть Entity, например, с именем '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

Я понятия не имею, как решить эту проблему. Кто-нибудь может помочь?

1 Ответ

0 голосов
/ 30 марта 2020

В этом случае я использовал столбец дискриминатора. это решило мою проблему.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...