-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: JavassistLazyInitializer returns null for getter of @Id
PostPosted: Thu Jul 03, 2008 12:32 am 
Newbie

Joined: Thu Jun 26, 2008 12:50 am
Posts: 9
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.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 08, 2008 12:47 am 
Newbie

Joined: Thu Jun 26, 2008 12:50 am
Posts: 9
Sorry to reply to my own post but I've found out a bit more.

I'm pretty desperate to know what's going wrong here, so I tried putting the id attribute and @Id annotated getter, directly on the Organisation, and not inheriting from AuditableIdentifiableEntity.

Unfortunately, I get exactly the same behaviour: the handler / target inside hte proxy looks fine, and the id attribute is printed OK in toString(), but when getId() is called, null is returned.

I've looked through the source code for JavassistLazyInitializer and all it's ancestors and can't see an getId() methods that cuold be conflicting.

Please, if anyone has ideas about what's going on - or even ways I can work around this - let me know.


Top
 Profile  
 
 Post subject: Re: JavassistLazyInitializer returns null for getter of @Id
PostPosted: Tue Mar 18, 2014 7:24 am 
Newbie

Joined: Fri Jan 03, 2014 3:32 am
Posts: 3
did you ever find a solution? I am having the same problem.

any support would be appreciated.

thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.