tags:

views:

92

answers:

1

I am working on an application which uses hibernate. When the object is returned from hibernate.,it is no longer a pojo.. there is something like cglibenhancer attached to it. because of it i cannot do any operations on it. i need to convert it to a java poja again. for this i am using hibernatebeanreplicator. what it does is that if the class had cglibenhancer attached to it.. it makes the object null. The problem comes when i am fetching just one or two properties of that object and i want to use them,but cos the class has cglibenhancer attached to it,it makes it null.. I want that only those properties which are not fetched should be mae null. let me make the scenario more clear with an example.

I have a class User

class User {
    long id;
    String name;
    Address address;
}

I have another class address

class Address {
    long addrId;
    String streetName;
    String city;
}

In my maping for User class , i store the addrId as a foreign key. Now i want to fetch user class data +address id only. but because i have not loaded the address class completely and it attaches cglibenhancer to it and my beanreplicator makes it null.

Is there a way to fetch the user class data+address id and make streetName and city null.

Thanks in advance,

Rima Desai

A: 

I don't think you can do what you want, though I don't see why you would want that either.

If you fetch a Person's Address, and for whatever reason Hibernate decides that the Address should be a CGLIB proxy, you can fetch the Address' ID without it going to hit the database. But of course if you try to fetch the street or city it will have to go to the database to fetch that data.

Adam Batkin
Thanks Adam for your reply. I want the address id for using it furter in the code. i require the street and the city information later on or i might not need it . Hibernate loads the id but my bean replicator makes it null because the class Address is not fully loaded. I need some way where in the loaded variables are not set to null.