Hey Gurus!
I'm not sure what i've done wrong, but ManyToMany relationship doesn't seem to work for me
here we go:
Entity1:
btw, I don't know why, but forum doesn't allow me to use AT charachter in my posts ... it thinks i'm trying to post URLsCode:Entity Table(name = "user_groups") public class UserGroup implements Serializable { ........ private List<UserTag> tags; ........ ManyToMany(mappedBy = "userGroups", cascade=CascadeType.ALL) public List<UserTag> getTags() { return tags; }so i've cut them off
Entity2:
And Dao method:Code:Entity Table(name = "user_tags") public class UserTag implements Serializable { ......... private List<UserGroup> userGroups = new ArrayList<UserGroup>(); .......... ManyToMany(cascade={CascadeType.PERSIST, CascadeType.MERGE}) JoinTable( name="user_tags_user_groups", joinColumns={JoinColumn(name="tags_id")}, inverseJoinColumns={JoinColumn(name="userGroups_id")} ) public List<UserGroup> getUserGroups() { return userGroups; }
That's it ... it persists userGroup entity to user_groups table, it persists userTags to user_tags table, but it DOESN'T persist anything to user_tags_user_groups table.. I know it must be something really stupid.Code:Transactional(propagation = Propagation.REQUIRED) public void persistUserGroup(UserGroup ug) { if (ug.getId() == null) getJpaTemplate().persist( ug ); else getJpaTemplate().merge( ug ); }
Here is the log-file:
it's obvious it knows about that table, but nothing happens to it apart from these strange chache messages and no joins at insert into user_tags tableCode:2008 Jul 08 00:26:42,715 [org.hibernate.cache.UpdateTimestampsCache][DEBUG] Pre-invalidating space [user_groups] 2008 Jul 08 00:26:42,716 [hibernate.jdbc.util.SQLStatementLogger][DEBUG] insert into user_groups (access, author_id, city, country, createdAt, description, geolocated, modifiedAt, name, region, status) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) 2008 Jul 08 00:26:42,719 [org.hibernate.cache.UpdateTimestampsCache][DEBUG] Pre-invalidating space [user_tags] 2008 Jul 08 00:26:42,721 [hibernate.jdbc.util.SQLStatementLogger][DEBUG] insert into user_tags (name) values (?) 2008 Jul 08 00:26:42,723 [org.hibernate.cache.UpdateTimestampsCache][DEBUG] Pre-invalidating space [user_tags] 2008 Jul 08 00:26:42,724 [hibernate.jdbc.util.SQLStatementLogger][DEBUG] insert into user_tags (name) values (?) 2008 Jul 08 00:26:42,726 [org.hibernate.transaction.JDBCTransaction][DEBUG] commit 2008 Jul 08 00:26:42,727 [org.hibernate.cache.UpdateTimestampsCache][DEBUG] Pre-invalidating space [user_tags_user_groups] 2008 Jul 08 00:26:42,727 [org.hibernate.cache.UpdateTimestampsCache][DEBUG] Pre-invalidating space [user_tags_user_groups] 2008 Jul 08 00:26:42,728 [org.hibernate.cache.UpdateTimestampsCache][DEBUG] Pre-invalidating space [user_tags_user_groups]![]()



so i've cut them off
Reply With Quote
