Код: Выделить всё
@Entity
@Table(name = "cas_base_accounts", schema = "connectors_account_service")
@Inheritance(strategy = InheritanceType.JOINED)
@Data
@SuperBuilder
@NoArgsConstructor
public abstract class BaseAccount {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(unique = true)
private Integer id;
//some fields here
Код: Выделить всё
@Entity
@Table(name = "cas_simple_auth_accounts", schema = "connectors_account_service")
@Inheritance(strategy = InheritanceType.JOINED)
@Data
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
@SuperBuilder
public class SimpleAuthAccount extends BaseAccount {
@Id
@GeneratedValue
private Integer id;
@NotNull
@JsonIgnore
private String clientId;
@NotNull
@JsonIgnore
private String clientSecret;
//some other fields
Код: Выделить всё
@Entity
@Table(name = "cas_oauth_accounts", schema = "connectors_account_service")
@Inheritance(strategy = InheritanceType.JOINED)
@Data
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
@SuperBuilder
public class OAuthAccount extends BaseAccount {
@Id
@GeneratedValue
private Integer id;
@JsonIgnore
private String state;
@JsonIgnore
private LocalDateTime stateExpirationTime;
@Transient
private String tokenLink;
//some fields
Код: Выделить всё
threw exception [Request processing failed; nested exception is org.springframework.orm.jpa.JpaSystemException: Cannot instantiate abstract class or interface: :
test.connectorsaccountservice.accountservice.model.BaseAccount; nested exception is org.hibernate.InstantiationException: Cannot instantiate abstract class or interface: : test.connectorsaccountservice.accountservice.model.BaseAccount]
Это показывает, что в этом методе возникает ошибка:
Код: Выделить всё
public Mono getAccountIds(Integer cabinetId) {
return findServiceByCabinetId(cabinetId)
.then(Mono.fromCallable(() -> baseAccountRepository.findByCabinetId(cabinetId)))
.flatMapIterable(e -> e)
.filter(oAuthAccount -> !oAuthAccount.getIsDeleted()
&& UserStatus.ENABLED.equals(oAuthAccount.getUserStatus()))
.map(BaseAccount::getId)
.collectList();
}
Код: Выделить всё
.then(Mono.fromCallable(() -> baseAccountRepository.findByCabinetId(cabinetId)))
Код: Выделить всё
public interface BaseAccountRepository extends JpaRepository {
Optional findByIdAndCabinetId(Integer accountId, Integer cabinetId);
Optional findByCabinetIdAndAccountLogin(Integer cabinetId, String accountLogin);
List findByCabinetId(Integer cabinetId);
Код: Выделить всё
@Repository
public interface SimpleAuthAccountRepository extends
JpaRepository,
CustomAccountRepository {
@Query("SELECT a FROM SimpleAuthAccount a " +
"JOIN BaseCabinet c ON a.cabinetId = c.id " +
"WHERE " +
"(:realmId IS NULL OR a.realmId = :realmId) AND " +
"(:accountLogin IS NULL OR a.accountLogin = :accountLogin) AND " +
"(:accountId IS NULL OR a.id = :accountId) AND " +
"(:cabinetId IS NULL OR a.cabinetId = :cabinetId) AND " +
"(:isDeleted IS NULL OR a.isDeleted = :isDeleted) AND " +
"((:advertiserIds) IS NULL OR a.advertiserId IN (:advertiserIds)) " +
"ORDER BY c.description, a.accountLogin")
List findAccounts(
@Param("realmId") Integer realmId,
@Param("accountLogin") String accountLogin,
@Param("accountId") Integer accountId,
@Param("cabinetId") Integer cabinetId,
@Param("isDeleted") Boolean isDeleted,
@Param("advertiserIds") Set advertiserIds
);
}
Как исправить? И почему это произошло и почему это все еще происходит после отмены изменений?
Думаю, добавление @DiscriminatorColumn и @DiscriminatorValue может помочь? Для меня существующий столбец CabinetId подойдет как @DiscriminatorColumn, но как мне установить для него значение, если у меня есть массив идентификаторов для SimpleAuthAccount и массивы идентификаторов для OAuthAccount? Я действительно не хочу добавлять еще один столбец в эту таблицу. Но, конечно, если здесь больше нет решений, я мог бы добавить столбец типа auth_type и установить SIMPLE_AUTH и OAUTH для этих классов.
Подробнее здесь: https://stackoverflow.com/questions/790 ... t-class-or