-->
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.  [ 8 posts ] 
Author Message
 Post subject: Don't want to load some basic properties of an entity
PostPosted: Mon Sep 01, 2008 4:13 pm 
Beginner
Beginner

Joined: Mon Sep 01, 2008 9:35 am
Posts: 24
Is there a way to specify that some attributes should not be loaded with hibernate queries?

For example, a User entity has a password property.
But I don't want to keep loading the password every time I load a User entity, since I only need it for registration (insert) and for authentication (a query that returns 1 if it finds a user with a given username and password).

If something like that doesn't exist, it should.
It is just like the 'update' and 'insert' properties of the mapping.

Thanks in advice.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 02, 2008 1:54 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
You can tag a property with lazy="true", but it also requires byte-code instrumentation of your compiled code. See http://www.hibernate.org/hib_docs/v3/re ... properties


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 02, 2008 12:20 pm 
Newbie

Joined: Tue Sep 02, 2008 12:15 pm
Posts: 1
I've been looking at hibernate, over the last few days and have come across the same issue,

It appears (I have not tried yet)
that you could extend the default PropertyAccessors that you are using to return a setter that does nothing.

Which may get the job done but it does seem like there should be an easier way.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 02, 2008 3:37 pm 
Beginner
Beginner

Joined: Mon Sep 01, 2008 9:35 am
Posts: 24
Hi,

Thanks for the reply.

I had already thought in using the instrumentation thing, but i think it is not possible in my case because the entity will be serialized to the GWT client. And in my case, it will trow an exception when it tries to get the property, because the transaction will already be closed. And even if the transaction is open, it will fetch the lazy property, and that is not what I want.

Can anyone give me some more information about how to use PropertyAccessors in Hibernate.

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 02, 2008 4:09 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
What about an empty setter method?

Code:
public void setPassword(String pwd)
{}


You probably need to map the password with update="false", otherwise Hibernate will clear it when you commit a transaction. If you want to update the password you'll need to use some other mechanism. I don't know if HQL-update works, but you should at least be able to use plain SQL for this.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 02, 2008 6:41 pm 
Beginner
Beginner

Joined: Mon Sep 01, 2008 9:35 am
Posts: 24
An empty setter would be okay in some cases.
But there two cases where I don't want to fetch data from the database:

1. Loading images (byte[]).
2. Loading a big geometry type (using PostGIS).

So, using an empty setter is not an option for me too.
I know I could remove these properties from the hibernate mapping, but it would be better if I could map them, so that I can use them in HQL.

Regards.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 03, 2008 2:47 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
It's moving away from the "simple" password case. It's kind of hard to give suggestions if we only have half the picture.

If it is a requirement that Hibernate should not SELECT the properties. The only way I know to do this is to map the properties as lazy and do the byte-code instrumentation or to put those properties as separate entities in separate tables and map them with <many-to-one> or <one-to-one>.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 03, 2008 5:31 am 
Newbie

Joined: Tue Jul 22, 2008 5:19 am
Posts: 10
I read on the link http://www.hibernate.org/hib_docs/v3/re ... properties
that "A different (better?) way to avoid unnecessary column reads, at least for read-only transactions is to use the projection features of HQL or Criteria queries. " an example using Criteria, to exclude a columns from select?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.