-->
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.  [ 11 posts ] 
Author Message
 Post subject: Hibernate re-uses key value for returned object: Switch off?
PostPosted: Thu Jan 15, 2004 5:28 pm 
Regular
Regular

Joined: Tue Jan 06, 2004 3:32 pm
Posts: 80
Location: Munich, Germany
My MySQL database is configured to use case insensitive searches.

session.load/get seems to re-use the key value for the object that is returned:

session.get(User.class, "bob").getName() returns "bob" even if the users.name primay key column in the database contains "BOB".

Hibernate saves on only fetching the other columns.

Can this behaviour be switched off somehow? I'd like to authenticate users case-insensitive with session.get() but then be able to use their correctly cased name.

Regards,

Andreas


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 15, 2004 5:43 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
I find this very hard to believe. Are you using a proxy?

Anyways you really shouldn't do something like that. Use a HQL query with lower(user.name) = "anything" and use a properly set up database.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 22, 2004 5:33 pm 
Regular
Regular

Joined: Tue Jan 06, 2004 3:32 pm
Posts: 80
Location: Munich, Germany
I'm not using proxies. Here is an example:

User u1 = (User) session.load(User.class, "user");
User u2 = (User) session.load(User.class, "USER");
System.out.println(u1);
System.out.println(u2);
System.out.println(u1 == u2);

outputs:

User[name=user]
User[name=USER]
false

I think especially the u1 != u2 is a bug, because its the same row in the database.

Regards,

Andreas


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 22, 2004 5:36 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Even if that is the case, I don't think Hibernate will be changed in a way to support a load with two different ids actually returning the same object. Don't know about the reuse part though ...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 22, 2004 5:46 pm 
Regular
Regular

Joined: Tue Jan 06, 2004 3:32 pm
Posts: 80
Location: Munich, Germany
Then perhaps it should be noted in the documentation somewhere that Hibernate doesn't support case insensitive identities.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 22, 2004 6:20 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
You can overide equals and hashCode of User class to fit your needs

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 22, 2004 6:35 pm 
Regular
Regular

Joined: Tue Jan 06, 2004 3:32 pm
Posts: 80
Location: Munich, Germany
Overriding equals and hashCode does not affect the behaviour of session.load() or the == operator.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 22, 2004 6:54 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
No but the proper usage System.out.println(u1.equals(u2)) would work.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 22, 2004 7:21 pm 
Regular
Regular

Joined: Tue Jan 06, 2004 3:32 pm
Posts: 80
Location: Munich, Germany
Still there is no persistent identity.

For persistent identity, you can safely use == as long both objects are loaded in the same Session (taken from the documentation).


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 23, 2004 3:44 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Post it to JIRA please

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 26, 2004 10:40 am 
Regular
Regular

Joined: Tue Jan 06, 2004 3:32 pm
Posts: 80
Location: Munich, Germany
Done.

See key HB-647.

http://opensource.atlassian.com/project ... key=HB-647


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