Hi! I could use a little help getting started with Hibernate ORM, mapping, and associations. In particular, I’m getting this runtime error which is a little puzzling:
org.hibernate.AnnotationException: Association 'model.Account.orders' targets the type 'model.Order' which is not an '@Entity' type
This is puzzling to me because my model.Order
Java POJO does have the @Entity
annotation. Being POJOs, there’s not much to them, but FWIW here they are. I’m sure I’m overlooking something silly, but I don’t quite see it yet. Any insights would be greatly appreciated. Thanks!
package model;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
@Entity
public class Account {
@Id @GeneratedValue
public UUID id;
public String name;
@Column(name = "created_at") @CreationTimestamp
public LocalDateTime createdAt;
@Column(name = "updated_at") @UpdateTimestamp
public LocalDateTime updatedAt;
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
public List<Order> orders = new ArrayList<>();
}
package model;
import java.time.LocalDateTime;
import java.util.UUID;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
@Entity
public class Order {
@Id @GeneratedValue
public UUID id;
public UUID accountId;
public String status;
public String value;
@Column(name = "created_at") @CreationTimestamp
public LocalDateTime createdAt;
@Column(name = "updated_at") @UpdateTimestamp
public LocalDateTime updatedAt;
@ManyToOne @JoinColumn(name = "account_id")
public Account account;
}