In my Spring Boot application, I have two models. Actually trying to implement ManyToMany relationship.
A:
@Entity
public class A {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private Set<B> b=new HashSet<>();
public A() {
}
}
B:
@Entity
public class B {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private Set<A> a=new HashSet<>();
public B() {
}
}
When I try to compile this this gives me error, saying : Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Could not determine type for: java.util.Set, at table: a, for columns: [org.hibernate.mapping.Column(b)]
Full log : here
ManyToOneor other? Also id does not make sense toBhavingSetofAand vice versa. If you meanManyToManyrelationship, it does not work like that - Houssem BadriManyToManyrelationship @HoussemBadri - Maifee Ul Asad@ManyToManyrelationship, where have you implement it? - PatrickManyToManyrelation you need to add an intermediate table, that relationship would be change toOneToMnayandManyToOne. Have a look at this link: baeldung.com/hibernate-many-to-many - Houssem Badri@JoinTable(name ="...",joinColumns = @JoinColumn(name = "..."), inverseJoinColumns = @JoinColumn(name = "..."))... And this works, and creates table. But the problem is I don't know how to retrieve data from this table? And I'm not sure if they are updating or not .. - Maifee Ul Asad