[hibernate-issues] [Hibernate-JIRA] Created: (HHH-5497) TABLE_PER_CLASS with reflexive dependency and join table leads to invalid SQL (JoinTable-annotation is ignored)

Michael Ernst (JIRA) noreply at atlassian.com
Tue Aug 24 07:42:41 EDT 2010


TABLE_PER_CLASS with reflexive dependency and join table leads to invalid SQL (JoinTable-annotation is ignored)
---------------------------------------------------------------------------------------------------------------

                 Key: HHH-5497
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5497
             Project: Hibernate Core
          Issue Type: Bug
    Affects Versions: 3.5.5
         Environment: Hibernate-3.5.5
H2Dialect (H2)
            Reporter: Michael Ernst


Join Table statement is ignored for selects. The following configuration works fine with JOINED or SINGLE_TABLE inheritance strategy but leads to the following error in case of TABLE_PER_CLASS (it also works fine if I remove the @JoinTable annotation):
{code}
@Entity
@Table( name = "IM_GROUP" )
public class Group extends AbstractOrgaUnit implements IGroup
{
   @OneToMany( targetEntity = Group.class,
               cascade = { CascadeType.PERSIST, CascadeType.MERGE,
      				CascadeType.REFRESH, CascadeType.DETACH }, orphanRemoval = false,
               mappedBy = "parentGroup" )
   private Set<IGroup>       subGroups;

   @ManyToOne( targetEntity = Group.class,
               cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH, CascadeType.DETACH } )
   @JoinTable( name = "IM_GROUP_PARENT_GROUP", joinColumns = @JoinColumn( name = "PARENT_GROUP_IM_GROUP_ID",
                                                                          referencedColumnName = "ID" ),
               inverseJoinColumns = @JoinColumn( name = "SUB_GROUPS_IM_GROUP_ID", referencedColumnName = "ID" ) )
   private IGroup            parentGroup;
   ...
{code}

Create Table statements:
{noformat}
create table IM_GROUP (ID bigint not null, UUID varchar(255) not null unique,  
	NAME varchar(255) not null, M_VERSION bigint, primary key (ID))
create table IM_GROUP_PARENT_GROUP (SUB_GROUPS_IM_GROUP_ID bigint, PARENT_GROUP_IM_GROUP_ID bigint not null, primary key (PARENT_GROUP_IM_GROUP_ID))
{noformat}
Select error:
{noformat}
Column "GROUP1_.SUB_GROUPS_IM_GROUP_ID" not found; SQL statement:
select 	groups0_.GROUPS_USER_ID as GROUPS1_0_2_, 
		groups0_.GROUPS_IM_GROUP_ID as GROUPS2_2_, 
		group1_.ID as ID0_0_, 
		group1_.UUID as UUID0_0_, 
		group1_.NAME as NAME0_0_, 
		group1_.M_VERSION as M12_0_0_, 
		group1_.SUB_GROUPS_IM_GROUP_ID as SUB1_5_0_, 
		group2_.ID as ID0_1_, 
		group2_.UUID as UUID0_1_, 
		group2_.NAME as NAME0_1_, 
		group2_.M_VERSION as M12_0_1_, 
		group2_.SUB_GROUPS_IM_GROUP_ID as SUB1_5_1_ 
	from USER_GROUPS groups0_ inner join IM_GROUP group1_ on groups0_.GROUPS_IM_GROUP_ID=group1_.ID left outer join IM_GROUP group2_ on group1_.SUB_GROUPS_IM_GROUP_ID=group2_.ID 
	where groups0_.GROUPS_USER_ID=? [42122-125]
	at org.h2.message.Message.getSQLException(Message.java:111)
	at org.h2.message.Message.getSQLException(Message.java:122)
	...
{noformat}


-- 
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