2

While working in a Spring Boot project, I used JPA to map the entities in the database, but unfortunately I came across this error:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: @OneToOne or @ManyToOne on com.userFront.domain.SavingsTransaction.savingsAccount references an unknown entity: com.userFront.domain.SavingsAccount

From what I understand, the problem lies in the relationship between these two classes. According to my conception I think that all the annotations are correct and the logic is right.

This is the SavingsAccount class:

package com.userFront.domain; import java.math.BigDecimal; import java.util.List; import javax.persistence.CascadeType; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.OneToMany; import net.minidev.json.annotate.JsonIgnore; public class SavingsAccount { @Id @GeneratedValue(strategy=GenerationType.AUTO) private Long id ; private int accountNumber; private BigDecimal accountBalance; @OneToMany(mappedBy="savingsAccount",cascade=CascadeType.ALL,fetch=FetchType.LAZY) @JsonIgnore private List<SavingsTransaction > SavingsTransactionList; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public int getAccountNumber() { return accountNumber; } public void setAccountNumber(int accountNumber) { this.accountNumber = accountNumber; } public BigDecimal getAccountBalance() { return accountBalance; } public void setAccountBalance(BigDecimal accountBalance) { this.accountBalance = accountBalance; } public List<SavingsTransaction> getSavingsTransactionList() { return SavingsTransactionList; } public void setSavingsTransactionList(List<SavingsTransaction> savingsTransactionList) { SavingsTransactionList = savingsTransactionList; } } 

And this is SavingsTransaction Class:

package com.userFront.domain; import java.math.BigDecimal; import java.util.Date; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; @Entity public class SavingsTransaction { @Id @GeneratedValue(strategy=GenerationType.AUTO) private Long id ; private Date date ; private String description ; private String type ; private String status ; private double amount; private BigDecimal availableBalance ; @ManyToOne @JoinColumn(name="savings_account_id") private SavingsAccount savingsAccount; public SavingsTransaction() {} public Long getId() { return id; } public void setId(Long id) { this.id = id; } public Date getDate() { return date; } public void setDate(Date date) { this.date = date; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public String getType() { return type; } public void setType(String type) { this.type = type; } public String getStatus() { return status; } public void setStatus(String status) { this.status = status; } public double getAmount() { return amount; } public void setAmount(double amount) { this.amount = amount; } public BigDecimal getAvailableBalance() { return availableBalance; } public void setAvailableBalance(BigDecimal availableBalance) { this.availableBalance = availableBalance; } public SavingsAccount getSavingsAccount() { return savingsAccount; } public void setSavingsAccount(SavingsAccount savingsAccount) { this.savingsAccount = savingsAccount; } public SavingsTransaction(Date date, String description, String type, String status, double amount, BigDecimal availableBalance, SavingsAccount savingsAccount) { super(); this.date = date; this.description = description; this.type = type; this.status = status; this.amount = amount; this.availableBalance = availableBalance; this.savingsAccount = savingsAccount; } } 

1 Answer 1

2

Your SavingsAccount class is not annotated with @Entity. Could you try and see if that fixes it?

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.