[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-2883) ManyToMany doesn't work with polymorfism

Dirk (JIRA) noreply at atlassian.com
Mon Sep 29 03:20:04 EDT 2008


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-2883?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=31294#action_31294 ] 

Dirk commented on HHH-2883:
---------------------------

While I see from time to time cosmetic changes in Hibernate, after almost a year and having written a test case (as requested) I see Hibernate is still not able to do the basics : Object Relational Mapping. I think that Polyformism is one of the basics of OO and should be supported out of the box.

> ManyToMany doesn't work with polymorfism
> ----------------------------------------
>
>                 Key: HHH-2883
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2883
>             Project: Hibernate Core
>          Issue Type: Bug
>    Affects Versions: 3.2.4
>         Environment: Hibernate 3.2.4, Annotations 3.3.0, Entitymanager 3.3.0
>            Reporter: Dirk
>         Attachments: ManyToMany-Hibernate325.zip
>
>
> We tried out the SingleTable inheritance with a ManyToMany
> @Entity
> @Table(name="SHB_PRINCIPAL")
> @Inheritance(strategy=InheritanceType.SINGLE_TABLE)
> @DiscriminatorColumn(name="TYPE",discriminatorType=DiscriminatorType.INTEGER)
> @Cache(usage=CacheConcurrencyStrategy.TRANSACTIONAL)
> public class Principal implements Serializable {
> ....
> @Entity
> @DiscriminatorValue(PrincipalType.USER_NR)
> @Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
> public class ApplicationUser extends Principal {
> private static final long serialVersionUID = 1L;
> @ManyToMany(fetch=FetchType.LAZY, cascade={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH},
> targetEntity=Role.class)
> @JoinTable(name="SHB_PRINCIPAL_TO_PRINCIPAL",
> joinColumns=@JoinColumn(name="FROM_PRINCIPAL_ID"),
> inverseJoinColumns=@JoinColumn(name="TO_PRINCIPAL_ID"))
> private Set<Role> roles;
> @ManyToMany(fetch=FetchType.LAZY, cascade={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH},
> targetEntity=ApplicationGroup.class)
> @JoinTable(name="SHB_PRINCIPAL_TO_PRINCIPAL",
> joinColumns=@JoinColumn(name="FROM_PRINCIPAL_ID"),
> inverseJoinColumns=@JoinColumn(name="TO_PRINCIPAL_ID"))
> private Set<ApplicationGroup> groups;
> @Entity
> @DiscriminatorValue(PrincipalType.GROUP_NR)
> @Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
> public class ApplicationGroup extends Principal {
> private static final long serialVersionUID = 1L;
> @ManyToMany(fetch=FetchType.LAZY, cascade={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH})
> @JoinTable(name="SHB_PRINCIPAL_TO_PRINCIPAL",
> joinColumns=@JoinColumn(name="TO_PRINCIPAL_ID"),
> inverseJoinColumns=@JoinColumn(name="FROM_PRINCIPAL_ID"))
> private Set<ApplicationUser> users;
> public ApplicationGroup() {
> super();
> this.type = PrincipalType.GROUP;
> }
> public Set<ApplicationUser> getUsers() {
> return users;
> }
> public void setUsers(Set<ApplicationUser> users) {
> this.users = users;
> }
> }
> But in the groups and the roles of the user, hibernate returns all principals, not only the users or groups. In the query it's clear that the descriminator is NOT used.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list