-
Notifications
You must be signed in to change notification settings - Fork 41.3k
Closed
Description
Hi,
SpringPhysicalNamingStrategy
(applied by defaut by spring boot) does not work in this case.
@Entity
public class Book {
@Id
private int id;
@ElementCollection
private List<Comment> comments;
}
@Entity
public class User {
@Id
private int id;
@ElementCollection
@CollectionTable(name="book_comments")
private List<Comment> comments;
}
@Embeddable
public class Comment {
@ManyToOne
private User user;
@ManyToOne
private Book book;
private String text;
private Instant date;
}
error (when EntityManagerFactory
is created) : org.hibernate.MappingException: Repeated column in mapping for collection: Book.comments column: book_id
@Parent
cannot be used, because user
is not a parent if comments are accessed from the Book
, and book
is not a parent if comments are accessed from the User
.
Removing relations in Comment
solve the problem, setting the naming strategies (both physical and implicit) to hibernate default also solve the problem :
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl
I don't know if this mapping is officially supported by Hibernate, but if Hibernate default strategy works, it could also work withSpringPhysicalNamingStrategy
.
Metadata
Metadata
Assignees
Labels
type: documentationA documentation updateA documentation update