When a select is issued as illustrated, there is the expected JOIN issued, but then there is a select issued for every qts_person row that is a User instance; see generated SQL portion.
I'm stuck with the [some?] reference to the AuthUser object; a wrapper for a legacy table.
Is this a bogus strategy/mapping, or is there something else happening here?
Hibernate version:
3.2.0.cr2 (annotations)
Mapping documents:
(annotations, see code)
Code between sessionFactory.openSession() and session.close():
Here's reproducing code and annotated objects stripped to bare minimum:
Code:
Session s = HibernateUtil.getSession();
s.beginTransaction();
Criteria q = s.createCriteria( Person.class ).add( Restrictions.eq( "lastName", "Newman" ) );
List l = q.list();
System.out.println(l.size());
s.getTransaction().rollback();
annotated classes involved:
Code:
@Entity
@Table( name="qts_person" )
@Inheritance( strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn( name="person_class" )
public class Person {
private Long id;
private String lastName;
@Id
@GeneratedValue( strategy=GenerationType.AUTO, generator="SEQ_GEN" )
public Long getId() { return id; }
public void setId( Long in ) { id = in; }
@Column( name="last_name", nullable=false )
public String getLastName() { return lastName; }
public void setLastName(String lastName) { this.lastName = (lastName != null)?lastName.trim():null; }
}
Code:
@Entity
@DiscriminatorValue( "User" )
public class User extends Person {
private AuthUser authUser;
public User() {}
public User( AuthUser user ) {
setAuthUser( user );
}
@OneToOne
@Fetch( FetchMode.JOIN)
@JoinColumn( name="authuser_auth_userid")
public AuthUser getAuthUser() {
return authUser;
}
public void setAuthUser(AuthUser authUser) {
this.authUser = authUser;
}
}
Code:
@Entity
@Table( name="auth_users_data" )
public class AuthUser {
private Long _id;
public AuthUser() {}
@Id
@Column( name="AUTH_USERID" )
public Long getId() {
return _id;
}
public void setId(Long id) {
_id = id;
}
}
Full stack trace of any exception that occurs:not an exception; see generated SQL
Name and version of the database you are using:Oracle 9i
The generated SQL (show_sql=true):Code:
Hibernate: select this_.id as id0_3_, this_.create_ts as create3_0_3_, this_.creator_id as creator10_0_3_, this_.updater_id as updater11_0_3_, this_.u
pdate_ts as update4_0_3_, this_.active as active0_3_, this_.first_name as first6_0_3_, this_.last_name as last7_0_3_, this_.middle_name as middle8_0_3
_, this_.email as email0_3_, this_.authuser_auth_userid as authuser12_0_3_, this_.person_class as person1_0_3_, person2_.id as id0_0_, person2_.create
_ts as create3_0_0_, person2_.creator_id as creator10_0_0_, person2_.updater_id as updater11_0_0_, person2_.update_ts as update4_0_0_, person2_.active
as active0_0_, person2_.first_name as first6_0_0_, person2_.last_name as last7_0_0_, person2_.middle_name as middle8_0_0_, person2_.email as email0_0
_, person2_.authuser_auth_userid as authuser12_0_0_, person2_.person_class as person1_0_0_, person3_.id as id0_1_, person3_.create_ts as create3_0_1_,
person3_.creator_id as creator10_0_1_, person3_.updater_id as updater11_0_1_, person3_.update_ts as update4_0_1_, person3_.active as active0_1_, pers
on3_.first_name as first6_0_1_, person3_.last_name as last7_0_1_, person3_.middle_name as middle8_0_1_, person3_.email as email0_1_, person3_.authuser
_auth_userid as authuser12_0_1_, person3_.person_class as person1_0_1_, authuser4_.AUTH_USERID as AUTH1_10_2_ from qts_person this_ inner join qts_per
son person2_ on this_.creator_id=person2_.id left outer join qts_person person3_ on person2_.updater_id=person3_.id left outer join auth_users_data au
thuser4_ on person3_.authuser_auth_userid=authuser4_.AUTH_USERID where this_.last_name=?
Hibernate: select authuser0_.AUTH_USERID as AUTH1_10_0_ from auth_users_data authuser0_ where authuser0_.AUTH_USERID=?
Hibernate: select authuser0_.AUTH_USERID as AUTH1_10_0_ from auth_users_data authuser0_ where authuser0_.AUTH_USERID=?
Hibernate: select authuser0_.AUTH_USERID as AUTH1_10_0_ from auth_users_data authuser0_ where authuser0_.AUTH_USERID=?
Debug level Hibernate log excerpt: