PersistentObjectException: detached entity passed to persist thrown by JPA and Hibernate

前端 未结 18 2631
醉酒成梦
醉酒成梦 2020-11-22 05:10

I have a JPA-persisted object model that contains a many-to-one relationship: an Account has many Transactions. A Transaction has one

18条回答
  •  执念已碎
    2020-11-22 05:42

    In your entity definition, you're not specifying the @JoinColumn for the Account joined to a Transaction. You'll want something like this:

    @Entity
    public class Transaction {
        @ManyToOne(cascade = {CascadeType.ALL},fetch= FetchType.EAGER)
        @JoinColumn(name = "accountId", referencedColumnName = "id")
        private Account fromAccount;
    }
    

    EDIT: Well, I guess that would be useful if you were using the @Table annotation on your class. Heh. :)

提交回复
热议问题