Hibernate cannot correctly load Locale in a @EmbeddedId key

Description

The whole description (with pretty code formatting) is in this thread : http://stackoverflow.com/questions/3825729/hibernate-search-unable-to-load-entities-with-composite-primary-keys
To make it clear , I found an @EmbeddedId cannot correctly load Locale property!
Suppose I have an @EmbeddedId with an integer and a locale , composing a composite primary key.
And if the locale column in DB is storing "zh_TW" , it should build a Locale("zh" , "TW") object , with language=zh , country=Taiwan.
But the loaded locale is language="zh_tw" , without country value! It will invalidate the equals()/hashCode() contract.
And lucene will log "Object found in Search index but not in database" !

But if I remove the @EmbeddedId and use a surrogate key , the locale can be loaded correctly !
So it is a bug , but I am not sure it is from hibernate or hibernate-search.

Attachments

1

Activity

Show:

Smallufo Huang September 30, 2010 at 11:22 AM

I combine "index" and "locale" with a white space in objectToString() , so index=1 , locale=zh_TW is combined to "1 zh_TW" . And in stringToObject() , besides splitting index and locale with whitespace , I should also split "zh_TW" with underline , to build correct language and country (and variant)... , Otherwise , new Locale("zh_TW") will build a lang="zh_tw" locale .

Sanne Grinovero September 30, 2010 at 11:12 AM

I don't think you should tokenize the locale code at all, but yes this is not a bug in Search

Smallufo Huang September 30, 2010 at 10:15 AM

It's TwoWayStringBridge's fault , I should advance StringTokenize locale String with '_' to build correct Locale object. The problem should be marked closed or Not_a_problem.

Sanne Grinovero September 30, 2010 at 8:31 AM

the Locale is loaded by your fieldBridge: NameKeyBridge's implementation should care for this. Is it a TwoWayFieldBridge? if yes, it's creating the locale starting from the encoded locale String, if not it should have thrown an exception as fields marked as identifiers should be twoway.

Smallufo Huang September 30, 2010 at 4:18 AM

debugger info , we can observe the locale is not correctly loaded.

Rejected

Details

Assignee

Reporter

Components

Affects versions

Priority

Created September 30, 2010 at 3:57 AM
Updated September 11, 2011 at 6:20 PM
Resolved September 30, 2010 at 11:12 AM