我正在尝试解决此派生身份的问题。在我的Spring Boot服务中,当我尝试保留LoanInfo()时,出现此错误:
java.lang.IllegalArgumentException: This class [class org.onewallet.entity.Loan] does not define an IdClass
ID的生成在AbstractPersistableCustom.java中进行处理:
@MappedSuperclass
public class AbstractPersistableCustom <PK extends Serializable> implements Persistable<Long> {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Override
public Long getId() {
return id;
}
/**
* Sets the id of the entity.
*
* @param id the id to set
*/
protected void setId(final Long id) {
this.id = id;
}
/*
* (non-Javadoc)
*
* @see org.springframework.data.domain.Persistable#isNew()
*/
@Override
public boolean isNew() {
return null == this.id;
}
//We have removed toString(), hashCode() and equals() methods. By adding them end up issues with OpenJPA
}
在我的实体Loan.java中,我有:
@Entity
@Table(name="m_loan")
public class Loan extends AbstractPersistableCustom<Long> {
/** Disable optimistic locking till batch jobs failures can be fixed **/
@Version
int version;
....
....
}
阅读一些资料后,我尝试使用@IdClass注释实体:
@Entity
@IdClass(AbstractPersistableCustom.class)
@Table(name="m_loan")
public class Loan extends AbstractPersistableCustom<Long> {
/** Disable optimistic locking till batch jobs failures can be fixed **/
@Version
int version;
...
...
}
此更改后,当我尝试保留数据时,我得到另一个异常:
org.springframework.orm.jpa.JpaSystemException: Could not set field value [POST_INSERT_INDICATOR] value by reflection
关于如何解决这个问题的任何意见吗?