我有以下实体:
用户:
@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Entity
@Audited
@Table(name="user_account")
public class User extends AbstractAuditableEntity implements UserDetails {
private String email;
private String password;
private boolean enabled;
private String name;
@ManyToMany
@Audited(targetAuditMode = NOT_AUDITED)
private Set<Role> roles = new HashSet<>();
@ManyToOne
private Currency preferredCurrency;
货币:
@Data
@EqualsAndHashCode(callSuper = true)
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Audited
public class Currency extends AbstractAuditableEntity {
private String isoCode;
private String name;
private BigDecimal euroConversion;
private String symbol;
}
费用类型:
@Data
@EqualsAndHashCode(callSuper = true)
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Audited
public class ExpenseType extends AbstractAuditableEntity {
private String name;
private String description;
@ManyToOne(fetch = FetchType.LAZY)
private User user;
@ManyToOne
private ExpenseType parentExpenseType;
@OneToMany(mappedBy = "parentExpenseType", fetch = FetchType.LAZY)
private Set<ExpenseType> childExpenseTypes;
}
最后,费用:
@Data
@EqualsAndHashCode(callSuper = true)
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Entity
public class Expense extends AbstractAuditableEntity {
private String name;
private String description;
private LocalDateTime expenseDate;
private BigDecimal amount;
private boolean isIncome;
@ManyToOne
private Currency currency;
@ManyToOne
private ExpenseType expenseType;
@ManyToOne
private User user;
}
其父类AbstractAuditableEntity如下:
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
@Getter
@Setter
@Audited
@JsonIgnoreProperties({"createdBy", "lastModifiedBy", "createdDate", "lastModifiedDate" })
public abstract class AbstractAuditableEntity extends AbstractPersistable<Long> implements Serializable {
@JsonIgnore
@Version
protected Integer version;
@CreatedDate
@JoinColumn(name = "created_date", nullable = false, updatable = false)
protected LocalDateTime createdDate;
@LastModifiedDate
@JoinColumn(name = "last_modified_date")
protected LocalDateTime lastModifiedDate;
@CreatedBy
@ManyToOne
@JoinColumn(name = "created_by_id", nullable = false, updatable = false)
protected User createdBy;
@LastModifiedBy
@ManyToOne
@JoinColumn(name = "last_modified_by_id")
protected User lastModifiedBy;
}
当我尝试做的时候
repository.findById(id)
要获取“费用”实体,我收到以下错误:
org.hibernate.exception.GenericJDBCException:执行 SQL 的 JDBC 异常
[选择 e1_0.id,e1_0.金额,c1_0.id,c2_0.id,c2_0.created_by_id,c2_0.created_date,c2_0.email,c2_0.enabled,l1_0.id,l1_0.created_by_id,l1_0.created_date,l1_0.email ,l1_0.enabled,l1_0.last_modified_by_id,l1_0.last_modified_date,l1_0.name,l1_0.password,p1_0.id,c3_0.id,c3_0.created_by_id,c3_0.created_date,c3_0.email,c3_0.enabled,c3_0.last_modified_by_id,c3_0 .last_modified_date,c3_0.name,c3_0.password,c3_0.preferred_currency_id,c3_0.version,p1_0.created_date,p1_0.euro_conversion,p1_0.iso_code,l2_0.id,l2_0.created_by_id,l2_0.created_date,l2_0.email,l2_0.enabled ,l2_0.last_modified_by_id... 等等
什么实体可能导致此问题?我找不到错误。
我尝试将一些实体放入延迟加载,但说实话我真的需要加载它们。
用户拥有货币,但货币没有“createdBy”和“lastModifiedBy”之外的用户。 Expense 具有以下各项之一:User、Currency 和 ExpenseType。 ExpenseType 可以有一个父级,我需要它来加载所有的父级。
它在测试环境之外执行时有效,因此它只是测试类的“@Transactional”注释。