1
Good evening! I am having difficulty in carrying out the relationship of the entities and getting the following error below. I have tried to use other relationships, but to no avail. User may have multiple tickets / A ticket has only one user and one assignedUser and may have multiple changes / Are multiple changesStatus for one ticket and one user
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: @Column(s) not allowed on a @Manytoone Property: com.projecto.api.entites.Ticket.assignedUser
@Entity @Table(schema = "project_api", name = "user", uniqueConstraints = {@Uniqueconstraint(columnNames = {"name_user", "email"})}) public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "name_user")
@NotBlank
private String nameUser;
@Email
@NotBlank
private String email;
@Size(min = 6)
@NotBlank
private String password;
@OneToMany
@JoinColumn(name = "fk_ticket", foreignKey = @ForeignKey (name = "user_ticket_fk"))
private List<Ticket> tickets;
@Enumerated(EnumType.STRING)
private ProfileEnum profile;
}
@Entity @Table(schema = "project_api", name = "ticket", uniqueConstraints = @Uniqueconstraint(columnNames = {"number"})) public class Ticket {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "date_ticket")
private Date dateTicket;
private String title;
private Long number;
private String description;
private String image;
//Usuário que gerou o ticket
@ManyToOne
@JoinColumn(name = "fk_user", foreignKey = @ForeignKey(name = "ticket_user_fk"))
private User user;
//Usuário atribuído pelo Técnico
@ManyToOne
@Column(name = "assigned_user")
@JoinColumn(name = "fk_assigned_user", foreignKey = @ForeignKey(name = "ticket_assigned_user_fk"))
private User assignedUser;
@OneToMany
@JoinColumn(name = "fk_change_status", foreignKey = @ForeignKey(name = "ticket_change_status_fk"))
private List<ChangeStatus> changes;
@Enumerated(EnumType.STRING)
private StatusEnum status;
@Enumerated(EnumType.STRING)
private PriorityEnum priority;
}
@Entity @Table(schema = "project_api", name = "change_status") public class Changestatus {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne
@JoinColumn(name = "fk_ticket", foreignKey = @ForeignKey(name = "change_status_ticket_fk"))
private Ticket ticket;
@ManyToOne
@Column(name = "user_change")
@JoinColumn(name = "fk_user_change", foreignKey = @ForeignKey(name = "change_status_user_change_fk"))
private User userChange;
@Column(name = "date_change_status")
private Date dateChangeStatus;
@Enumerated(EnumType.STRING)
private StatusEnum status;
}
When using
@ManyToOne
cannot declare@Column
, remove where there are these two annotations in the same field, leaving only@ManyToOne
configuring with@JoinColumn
– nullptr
Thanks @nullptr worked. I’m starting with Java and other related technologies. I have a lot to learn. rs
– LiH