当前位置: 首页 > 知识库问答 >
问题:

在Spring Data Jpa中获取OneToMany映射实体时的StackOverflowError

龚奇逸
2023-03-14
**Entity 1**
@Entity
@Table(name = "Customer")
public class CustomerEntity implements Serializable {

    /** The Constant serialVersionUID. */
    private static final long serialVersionUID = 1L;

    /** The id. */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /** The first name. */
    @Column(name = "FirstName", length = 60, nullable = false)
    private String firstName;

    /** The last name. */
    @Column(name = "LastName", length = 60, nullable = false)
    private String lastName;

    /** The dob. */
    @Column(name = "DOB", nullable = false)
    private LocalDate dob;

    /** The mobile number. */
    @Column(name = "MobileNumber", length = 10, nullable = false, unique = true)
    private Long mobileNumber;

    /** The email id. */
    @Column(name = "Email", length = 100, nullable = false, unique = true)
    private String emailId;

    /** The address. */
    @Column(name = "Address", length = 255)
    private String address;

    /** The created time. */
    @Column(name = "CreatedTime", nullable = false)
    private LocalDateTime createdTime;

    /** The accounts. */
    @OneToMany(mappedBy = "customerEntity", cascade = CascadeType.ALL)
    private List<AccountEntity> accountEntities = new ArrayList<>();

    // Constructors, getters, setters, hashcode, equals, and toString methods are here
    @Override
    public String toString() {
        return "CustomerEntity [id=" + id + ", firstName=" + firstName + ", lastName=" + lastName + ", dob=" + dob
                + ", mobileNumber=" + mobileNumber + ", emailId=" + emailId + ", address=" + address + ", createdTime="
                + createdTime + ", accountEntities=" + accountEntities + "]";
    }

}
**Entity 2**
@Entity
@Table(name = "Account")
public class AccountEntity implements Serializable {

    /** The Constant serialVersionUID. */
    private static final long serialVersionUID = 1L;

    /** The id. */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /** The account number. */
    @Column(name = "AccountNumber", length = 20, nullable = false, unique = true)
    private String accountNumber;

    /** The branch. */
    @Column(name = "Branch", nullable = false)
    private String branch;

    /** The account type. */
    @Column(name = "AccountType", nullable = false)
    private String accountType;

    /** The balance. */
    @Column(name = "Balance", nullable = false)
    private Double balance;

    /** The created time. */
    @Column(name = "CreatedTime", nullable = false)
    private LocalDateTime createdTime;

    /** The account holder. */
    @ManyToOne(fetch = FetchType.LAZY)
    private CustomerEntity customerEntity;

   // Constructors, getters, setters, hashcode, equals, and toString methods are here

   @Override
    public String toString() {
        return "AccountEntity [id=" + id + ", accountNumber=" + accountNumber + ", branch=" + branch + ", accountType="
                + accountType + ", balance=" + balance + ", createdTime=" + createdTime + ", customerEntity="
                + customerEntity + "]";
    }
}

public Set<CustomerDTO> fetchCustomers(String searchKey) {
        List<CustomerEntity> customers = null;
        if (searchKey == null || searchKey.trim().isEmpty()) {
            **customers = customerRepository.findAll();**
        } else {
            **customers = customerRepository.findByFirstNameContainingIgnoreCaseOrLastNameContainingIgnoreCase(searchKey,
                    searchKey);**
        }
        System.out.println(customers);
        return customers.stream()
                .map(entity -> new CustomerDTO(entity.getId(), entity.getFirstName(), entity.getLastName(),
                        entity.getDob(), entity.getEmailId(), entity.getMobileNumber(), entity.getAddress(),
                        entity.getCreatedTime()))
                .collect(Collectors.toSet());
    }
Hibernate: select customeren0_.id as id1_1_, customeren0_.address as address2_1_, customeren0_.created_time as created_3_1_, customeren0_.dob as dob4_1_, customeren0_.email as email5_1_, customeren0_.first_name as first_na6_1_, customeren0_.last_name as last_nam7_1_, customeren0_.mobile_number as mobile_n8_1_ from customer customeren0_ where customeren0_.mobile_number=? or customeren0_.email=?
Hibernate: insert into customer (id, address, created_time, dob, email, first_name, last_name, mobile_number) values (null, ?, ?, ?, ?, ?, ?, ?)
Hibernate: select customeren0_.id as id1_1_0_, customeren0_.address as address2_1_0_, customeren0_.created_time as created_3_1_0_, customeren0_.dob as dob4_1_0_, customeren0_.email as email5_1_0_, customeren0_.first_name as first_na6_1_0_, customeren0_.last_name as last_nam7_1_0_, customeren0_.mobile_number as mobile_n8_1_0_ from customer customeren0_ where customeren0_.id=?
Hibernate: select accountent0_.id as id1_0_, accountent0_.account_number as account_2_0_, accountent0_.account_type as account_3_0_, accountent0_.balance as balance4_0_, accountent0_.branch as branch5_0_, accountent0_.created_time as created_6_0_, accountent0_.customer_entity_id as customer7_0_ from account accountent0_ left outer join customer customeren1_ on accountent0_.customer_entity_id=customeren1_.id where customeren1_.id=? and accountent0_.account_type=?
Hibernate: insert into account (id, account_number, account_type, balance, branch, created_time, customer_entity_id) values (null, ?, ?, ?, ?, ?, ?)
Hibernate: select customeren0_.id as id1_1_, customeren0_.address as address2_1_, customeren0_.created_time as created_3_1_, customeren0_.dob as dob4_1_, customeren0_.email as email5_1_, customeren0_.first_name as first_na6_1_, customeren0_.last_name as last_nam7_1_, customeren0_.mobile_number as mobile_n8_1_ from customer customeren0_ where upper(customeren0_.first_name) like upper(?) escape ? or upper(customeren0_.last_name) like upper(?) escape ?
Hibernate: select accountent0_.customer_entity_id as customer7_0_0_, accountent0_.id as id1_0_0_, accountent0_.id as id1_0_1_, accountent0_.account_number as account_2_0_1_, accountent0_.account_type as account_3_0_1_, accountent0_.balance as balance4_0_1_, accountent0_.branch as branch5_0_1_, accountent0_.created_time as created_6_0_1_, accountent0_.customer_entity_id as customer7_0_1_ from account accountent0_ where accountent0_.customer_entity_id=?
[2m2021-09-03 14:26:18.673[0;39m [31mERROR[0;39m [35m5812[0;39m [2m---[0;39m [2m[nio-8080-exec-4][0;39m [36mo.a.c.c.C.[.[.[/].[dispatcherServlet]   [0;39m [2m:[0;39m Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed; nested exception is java.lang.StackOverflowError] with root cause

java.lang.StackOverflowError: null
    at java.base/java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:582) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:175) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:87) ~[na:na]
    at java.base/java.lang.AbstractStringBuilder.<init>(AbstractStringBuilder.java:112) ~[na:na]
    at java.base/java.lang.StringBuilder.<init>(StringBuilder.java:127) ~[na:na]
    at com.assignment.bank.entities.AccountEntity.toString(AccountEntity.java:245) ~[classes/:na]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at java.base/java.util.AbstractCollection.toString(AbstractCollection.java:457) ~[na:na]
    at org.hibernate.collection.internal.PersistentBag.toString(PersistentBag.java:622) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at com.assignment.bank.entities.CustomerEntity.toString(CustomerEntity.java:297) ~[classes/:na]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at com.assignment.bank.entities.AccountEntity.toString(AccountEntity.java:247) ~[classes/:na]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at java.base/java.util.AbstractCollection.toString(AbstractCollection.java:457) ~[na:na]
    at org.hibernate.collection.internal.PersistentBag.toString(PersistentBag.java:622) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at com.assignment.bank.entities.CustomerEntity.toString(CustomerEntity.java:297) ~[classes/:na]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at com.assignment.bank.entities.AccountEntity.toString(AccountEntity.java:247) ~[classes/:na]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at java.base/java.util.AbstractCollection.toString(AbstractCollection.java:457) ~[na:na]
    at org.hibernate.collection.internal.PersistentBag.toString(PersistentBag.java:622) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at com.assignment.bank.entities.CustomerEntity.toString(CustomerEntity.java:297) ~[classes/:na]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at com.assignment.bank.entities.AccountEntity.toString(AccountEntity.java:247) ~[classes/:na]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at java.base/java.util.AbstractCollection.toString(AbstractCollection.java:457) ~[na:na]
    at org.hibernate.collection.internal.PersistentBag.toString(PersistentBag.java:622) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at com.assignment.bank.entities.CustomerEntity.toString(CustomerEntity.java:297) ~[classes/:na]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at com.assignment.bank.entities.AccountEntity.toString(AccountEntity.java:247) ~[classes/:na]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at java.base/java.util.AbstractCollection.toString(AbstractCollection.java:457) ~[na:na]
    at org.hibernate.collection.internal.PersistentBag.toString(PersistentBag.java:622) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at com.assignment.bank.entities.CustomerEntity.toString(CustomerEntity.java:297) ~[classes/:na]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at com.assignment.bank.entities.AccountEntity.toString(AccountEntity.java:247) ~[classes/:na]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at java.base/java.util.AbstractCollection.toString(AbstractCollection.java:457) ~[na:na]
    at org.hibernate.collection.internal.PersistentBag.toString(PersistentBag.java:622) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at com.assignment.bank.entities.CustomerEntity.toString(CustomerEntity.java:297) ~[classes/:na]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at com.assignment.bank.entities.AccountEntity.toString(AccountEntity.java:247) ~[classes/:na]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at java.base/java.util.AbstractCollection.toString(AbstractCollection.java:457) ~[na:na]
    at org.hibernate.collection.internal.PersistentBag.toString(PersistentBag.java:622) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at com.assignment.bank.entities.CustomerEntity.toString(CustomerEntity.java:297) ~[classes/:na]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at com.assignment.bank.entities.AccountEntity.toString(AccountEntity.java:247) ~[classes/:na]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at java.base/java.util.AbstractCollection.toString(AbstractCollection.java:457) ~[na:na]
    at org.hibernate.collection.internal.PersistentBag.toString(PersistentBag.java:622) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at com.assignment.bank.entities.CustomerEntity.toString(CustomerEntity.java:297) ~[classes/:na]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at com.assignment.bank.entities.AccountEntity.toString(AccountEntity.java:247) ~[classes/:na]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at java.base/java.util.AbstractCollection.toString(AbstractCollection.java:457) ~[na:na]
    at org.hibernate.collection.internal.PersistentBag.toString(PersistentBag.java:622) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at com.assignment.bank.entities.CustomerEntity.toString(CustomerEntity.java:297) ~[classes/:na]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at com.assignment.bank.entities.AccountEntity.toString(AccountEntity.java:247) ~[classes/:na]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at java.base/java.util.AbstractCollection.toString(AbstractCollection.java:457) ~[na:na]
    at org.hibernate.collection.internal.PersistentBag.toString(PersistentBag.java:622) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at com.assignment.bank.entities.CustomerEntity.toString(CustomerEntity.java:297) ~[classes/:na]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at com.assignment.bank.entities.AccountEntity.toString(AccountEntity.java:247) ~[classes/:na]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at java.base/java.util.AbstractCollection.toString(AbstractCollection.java:457) ~[na:na]
    at org.hibernate.collection.internal.PersistentBag.toString(PersistentBag.java:622) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at com.assignment.bank.entities.CustomerEntity.toString(CustomerEntity.java:297) ~[classes/:na]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at com.assignment.bank.entities.AccountEntity.toString(AccountEntity.java:247) ~[classes/:na]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at java.base/java.util.AbstractCollection.toString(AbstractCollection.java:457) ~[na:na]
    at org.hibernate.collection.internal.PersistentBag.toString(PersistentBag.java:622) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at com.assignment.bank.entities.CustomerEntity.toString(CustomerEntity.java:297) ~[classes/:na]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at com.assignment.bank.entities.AccountEntity.toString(AccountEntity.java:247) ~[classes/:na]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at java.base/java.util.AbstractCollection.toString(AbstractCollection.java:457) ~[na:na]
    at org.hibernate.collection.internal.PersistentBag.toString(PersistentBag.java:622) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at com.assignment.bank.entities.CustomerEntity.toString(CustomerEntity.java:297) ~[classes/:na]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at com.assignment.bank.entities.AccountEntity.toString(AccountEntity.java:247) ~[classes/:na]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at java.base/java.util.AbstractCollection.toString(AbstractCollection.java:457) ~[na:na]
    at org.hibernate.collection.internal.PersistentBag.toString(PersistentBag.java:622) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at com.assignment.bank.entities.CustomerEntity.toString(CustomerEntity.java:297) ~[classes/:na]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at com.assignment.bank.entities.AccountEntity.toString(AccountEntity.java:247) ~[classes/:na]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at java.base/java.util.AbstractCollection.toString(AbstractCollection.java:457) ~[na:na]
    at org.hibernate.collection.internal.PersistentBag.toString(PersistentBag.java:622) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at com.assignment.bank.entities.CustomerEntity.toString(CustomerEntity.java:297) ~[classes/:na]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at com.assignment.bank.entities.AccountEntity.toString(AccountEntity.java:247) ~[classes/:na]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at java.base/java.util.AbstractCollection.toString(AbstractCollection.java:457) ~[na:na]
    at org.hibernate.collection.internal.PersistentBag.toString(PersistentBag.java:622) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at com.assignment.bank.entities.CustomerEntity.toString(CustomerEntity.java:297) ~[classes/:na]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at com.assignment.bank.entities.AccountEntity.toString(AccountEntity.java:247) ~[classes/:na]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at java.base/java.util.AbstractCollection.toString(AbstractCollection.java:457) ~[na:na]
    at org.hibernate.collection.internal.PersistentBag.toString(PersistentBag.java:622) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at com.assignment.bank.entities.CustomerEntity.toString(CustomerEntity.java:297) ~[classes/:na]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at com.assignment.bank.entities.AccountEntity.toString(AccountEntity.java:247) ~[classes/:na]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at java.base/java.util.AbstractCollection.toString(AbstractCollection.java:457) ~[na:na]
    at org.hibernate.collection.internal.PersistentBag.toString(PersistentBag.java:622) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at com.assignment.bank.entities.CustomerEntity.toString(CustomerEntity.java:297) ~[classes/:na]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at com.assignment.bank.entities.AccountEntity.toString(AccountEntity.java:247) ~[classes/:na]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at java.base/java.util.AbstractCollection.toString(AbstractCollection.java:457) ~[na:na]
    at org.hibernate.collection.internal.PersistentBag.toString(PersistentBag.java:622) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at com.assignment.bank.entities.CustomerEntity.toString(CustomerEntity.java:297) ~[classes/:na]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at com.assignment.bank.entities.AccountEntity.toString(AccountEntity.java:247) ~[classes/:na]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at java.base/java.util.AbstractCollection.toString(AbstractCollection.java:457) ~[na:na]
    at org.hibernate.collection.internal.PersistentBag.toString(PersistentBag.java:622) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at com.assignment.bank.entities.CustomerEntity.toString(CustomerEntity.java:297) ~[classes/:na]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at com.assignment.bank.entities.AccountEntity.toString(AccountEntity.java:247) ~[classes/:na]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at java.base/java.util.AbstractCollection.toString(AbstractCollection.java:457) ~[na:na]
    at org.hibernate.collection.internal.PersistentBag.toString(PersistentBag.java:622) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at com.assignment.bank.entities.CustomerEntity.toString(CustomerEntity.java:297) ~[classes/:na]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at com.assignment.bank.entities.AccountEntity.toString(AccountEntity.java:247) ~[classes/:na]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at java.base/java.util.AbstractCollection.toString(AbstractCollection.java:457) ~[na:na]
    at org.hibernate.collection.internal.PersistentBag.toString(PersistentBag.java:622) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at com.assignment.bank.entities.CustomerEntity.toString(CustomerEntity.java:297) ~[classes/:na]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at com.assignment.bank.entities.AccountEntity.toString(AccountEntity.java:247) ~[classes/:na]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at java.base/java.util.AbstractCollection.toString(AbstractCollection.java:457) ~[na:na]
    at org.hibernate.collection.internal.PersistentBag.toString(PersistentBag.java:622) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at com.assignment.bank.entities.CustomerEntity.toString(CustomerEntity.java:297) ~[classes/:na]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at com.assignment.bank.entities.AccountEntity.toString(AccountEntity.java:247) ~[classes/:na]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at java.base/java.util.AbstractCollection.toString(AbstractCollection.java:457) ~[na:na]
    at org.hibernate.collection.internal.PersistentBag.toString(PersistentBag.java:622) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at com.assignment.bank.entities.CustomerEntity.toString(CustomerEntity.java:297) ~[classes/:na]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at com.assignment.bank.entities.AccountEntity.toString(AccountEntity.java:247) ~[classes/:na]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at java.base/java.util.AbstractCollection.toString(AbstractCollection.java:457) ~[na:na]
    at org.hibernate.collection.internal.PersistentBag.toString(PersistentBag.java:622) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at com.assignment.bank.entities.CustomerEntity.toString(CustomerEntity.java:297) ~[classes/:na]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at com.assignment.bank.entities.AccountEntity.toString(AccountEntity.java:247) ~[classes/:na]
    at java.base/java.lang.String.valueOf(String.java:3365) ~[na:na]
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:169) ~[na:na]
    at java.base/java.util.AbstractCollection.toString(AbstractCollection.java:457) ~[na:na]
    at org.hibernate.collection.internal.PersistentBag.toString(PersistentBag.java:622) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final]

共有1个答案

何兴邦
2023-03-14

关于Accountentity.class

 @Override
    public String toString() {
        return "AccountEntity [id=" + id + ", accountNumber=" + accountNumber + ", branch=" + branch + ", accountType="
                + accountType + ", balance=" + balance + ", createdTime=" + createdTime + ", customerEntity="
                + customerEntity + "]";
    }

您的toString()包括CustomerEntity,但是在CustomerEntity.class中还有一个AccountEntities 字段。

因此,您的.toString()方法得到对.toString()的递归调用,这最终导致stackoverflow错误。

 @Override
    public String toString() {
        return "AccountEntity [id=" + id + ", accountNumber=" + accountNumber + ", branch=" + branch + ", accountType="
                + accountType + ", balance=" + balance + ", createdTime=" + createdTime + ", customerEntityId="
                + customerEntity.getId() + "]";
    }

 类似资料:
  • 我们必须在可选元素“mappedby”中指定什么。是特定模型的table_name还是classname? 哪个是正确的? 这个

  • 问题内容: 我有一段维护代码,应该在某些时间点向某些用户授予选择特权: 我想对所有表执行此操作。我可以在Oracle或MySQL中使用它来获取完整列表,然后像这样继续前进。 但是由于我已经有了对象,所以我想知道是否还有另一种方法来获取所有映射的实体,经理知道(我正在使用Hibernate进行内部编程)。 问题答案: 我可以通过两种方式获取所有映射的实体及其对应的SQL表(可能还有其他)。 最直接的

  • 问题内容: 在我的项目中,我使用Entity Framework6。我有以下实体: 和 当我插入一个填充了PersonRights的人员对象时,它在数据库中看起来像这样: 人员实体表: PersonRights实体表 当我从数据库加载人时,它没有填充PersonRights属性,这是因为virtual关键字具有延迟加载功能-可以。 然后我得到了person对象的PersonRights,它也可以正

  • 我有MyEntity类: 在@RestController中有2个@GetMapping方法。第一个: 第二个: 需要提供: 1.@GetMap返回MyEntity类中描述的实体。 2.@GetMap("url")返回实体,就像它的一个字段带有@JsonIgnore一样。 更新: 例如,当我返回我的实体时,客户端将得到: 我想在同一时间使用相同的ENTITY有机会根据URL发送给客户端: 1. 2

  • 快速总结我想要实现的目标。请给出实施或设计建议:) 我有两个表:用户,图像。在UserDO中,我希望保留一组所有用户的图像,以及单个图像,即用户的肖像(在我的示例中,该组将包括肖像): 在ImageDO中,我有一个userid作为外键来记录哪个用户上传了图像。但是它没有布尔值,因为认为一个用户可能会上传许多图像,但只有一个是肖像。 有什么方法可以实现这一点吗?或者我需要维护另一个表(例如,Port

  • 我有以下模式: 项目(ID,名称)项目用户(项目ID,用户ID)用户(名称,ID) 实体如下 显然是一对多。项目可以有多个用户。 现在,我的目标是编写jooq查询,在那里我可以获取已经有相应用户的项目对象。 但是当预期约15时,查询将恢复千分之一的结果

  • 我试图在JPA中规划这种关系,但似乎在这里迷失了方向。这是我的ER型号说明。我有一个,其中一个客户有一个,这个包含股票。这就是我的想法。每个都有一个,即(关系)1:1,仓库可以包含更多的股份(库存)。仓库-- 我有以下代码。 Customer.java Depot.java 使用上面的代码,我甚至可以创建并持久化客户。我是不是做错了地图? 如果我试图将数据持久化到上面的数据库中,我会收到以下错误消

  • 我想询问一个人,并得到以下回应: 但在需要时,我还想包含字段,并获得如下内容: 但是,我得到的只是手机ID,就像这样: 这是两个有问题的领域: