Good day. There are three tables: "cars", "details" and "detail_car". Each table has an id, the "detail_car" still has car_id and detail_id columns. Those. cars and details are combined via the "detail_car" table. Here is the Car class:
@Entity @Table(name="CARS") public class Car { @Id @Column(name="id") private int id; @ManyToMany(cascade = CascadeType.ALL) @JoinTable( name = "detail_car", joinColumns = @JoinColumn(name = "car_id", referencedColumnName="id"), inverseJoinColumns = @JoinColumn(name = "detail_id", referencedColumnName="id")) private List<Detail> details; } In this case, the server console displays
SELECT this_.id AS id1_0_2_, this_.about AS about2_0_2_, this_.img_url AS img_url3_0_2_, this_.mark_id AS mark_id6_0_2_, this_.model_id AS model_id7_0_2_, this_.NICK AS NICK4_0_2_, this_.year AS year5_0_2_, mark2_.id AS id1_4_0_, mark2_.MARK AS MARK2_4_0_, model3_.id AS id1_5_1_, model3_.MODEL AS MODEL2_5_1_ FROM CARS this_ LEFT OUTER JOIN Marks mark2_ ON this_.mark_id=mark2_.id LEFT OUTER JOIN Models model3_ ON this_.model_id=model3_.id WHERE this_.id=? The error is: Unable to evaluate the expression Method threw 'org.hibernate.LazyInitializationException' exception.
How in the Car model to get the list of details belonging to this particular machine?
private List<Detail> detailsprecisely, you declared them and linked them to theHibernatetable. If everything is correct, you will fill in thedetailsvariable with data. It remains only to add getters and setters - JVicHibernate.initialize(details)structureHibernate.initialize(details)before using the parts list - JVic