This is an example of the project based on Vlad Mihalcea's post: The best way to map a many-to-many association with extra columns when using JPA and Hibernate
Stackoverflow questions: Russian:
Warning! The project was developed in the Intellij. It may not be compatible with Eclipse.
- Download repository
- In file
application.properties
add database connection properties. - If you are not using MySQL please change database connector in
pom.xml (look at the dependencies)
- Open the project
- Go to folder
ManyToManyWithExtraColumn/src/test/java/com/antonio112009/manyToMany/repository
- Open
PostRepositoryTest
- On the line 19 you will find run button (green arrow right). Press it and watch console.
- [FIXED] Unable to connect 2 or more object (that are in the database). Test number 3.
Error log:
org.springframework.orm.jpa.JpaSystemException: Could not set field value [SHORT_CIRCUIT_INDICATOR] value by reflection : [class com.antonio112009.manyToMany.entity.PostTagId.tagId]
setter of com.antonio112009.manyToMany.entity.PostTagId.tagId; nested exception is org.hibernate.PropertyAccessException: Could not set field value [SHORT_CIRCUIT_INDICATOR]
value by reflection : [class com.antonio112009.manyToMany.entity.PostTagId.tagId] setter of com.antonio112009.manyToMany.entity.PostTagId.tagId
- [FIXED with crutch] Unable to delete object with multiple objects.
- if we delete tag by calling
deleteByName(tagName)
, it should delete tag AND remove posts connected to it