We've got Organisation and User entities with a unidirection relaction ship from User to Organisation as follows:
Code:
class User extends AuditableIdentifiableEntity {
....
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "Org_Id", nullable = false)
public Organisation getOrganisation() {
return organisation;
}
....
}
Both User and Organisation extend our AuditableIdentifiableEntity class which is a MappedSupperClass that defines a Long id attribute as a generated primary key:
Code:
@MappedSuperclass
public abstract class AuditableIdentifiableEntity extends AuditableEntity {
...
Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public final Long getId() {
return this.id;
}
...
}
When we fetch a user from the DB via a query, I can call through and get the Organisation's attributes - except for the id as the following code & log output shows:
Code:
log.debug("setupMenusAndTransactions(): user.getOrganisation() [#0]", user.getOrganisation());
log.debug("setupMenusAndTransactions(): user.getOrganisation().getId() [#0]", user.getOrganisation().getId());
log.debug("setupMenusAndTransactions(): user.getOrganisation().getBrand() [#0]", user.getOrganisation().getBrand());
Code:
setupMenusAndTransactions(): user.getOrganisation() [Organisation = [5, Somewhere Out There]]
setupMenusAndTransactions(): user.getOrganisation().getId() [null]
setupMenusAndTransactions(): user.getOrganisation().getBrand() [Somewhere Out There]
The id is the only attribute that seems to have this problem - and because we can't get the Id, we can't use the Orgnaisation to do further lookups etc.
I've attached with a debugger and can see the Organsiation is actually a JavassistLazyInitializer that apears to be correctly setup with the real Organsiation in the target.
I'm wondering if there's a bug or gotcha using an id attribute from a MappedSuperclass, through the JavassistLazyInitializer?
Anyone how can help me out - I'd be very very grateful.
Thanks,
Hibernate version: 3.2.6.GA
Mapping documents: See above.
Code between sessionFactory.openSession() and session.close(): Relevant code is listed above.
Full stack trace of any exception that occurs: No exception
Name and version of the database you are using: MySql 5.0.51
The generated SQL (show_sql=true): Nope.
Debug level Hibernate log excerpt: If someone can tell me what debugging level to turn on I can provide it.