-->
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: Programmatic API document id bridge
PostPosted: Wed Oct 05, 2011 12:49 pm 
Newbie

Joined: Wed Oct 05, 2011 12:33 pm
Posts: 4
Hi,

I am currently trying to implement a problematic mapping for a given entity but have an issue. In the entity the ID is a UUID.. I can not find a way to register a bridge to handle the type. I have created and tested a bridge.

mapping.entity(Article.class).indexed().indexName("article")
.property("uid", ElementType.METHOD).documentId().field().bridge(HibernateSearchUUIDBridge.class)

Is there a way to do this? is it possible to register with hibernate a default bridge for a type?

Just a note to this. I can not use annotations and have to use java.util.UUID. a default bridge for UUID would be nice... the code would be simple..

@Override
public void set(String name, Object value, Document document,
LuceneOptions luceneOptions) {

UUID uid = (UUID)value;
Field field = new Field(name, uid.toString(), luceneOptions.getStore(), luceneOptions.getIndex(), luceneOptions.getTermVector());

document.add(field);
}


@Override
public String objectToString(Object object) {

UUID uid = (UUID)object;
return uid.toString();
}

@Override
public Object get(String name, Document document) {
String result = document.get(name);
UUID uid = UUID.fromString(result);
return (Object)uid;
}

Thanks,
Greg B.


Top
 Profile  
 
 Post subject: Re: Programmatic API document id bridge
PostPosted: Wed Oct 05, 2011 7:07 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi,
Quote:
mapping.entity(Article.class).indexed().indexName("article")
.property("uid", ElementType.METHOD).documentId().field().bridge(HibernateSearchUUIDBridge.class)
Is there a way to do this? is it possible to register with hibernate a default bridge for a type?


I'm not sure if I understood the question; are you saying that this code is not working?
Or just that you would like to register the HibernateSearchUUIDBridge for all UUID instances, to be applied automatically? That is currently not possible.

Quote:
Just a note to this. I can not use annotations and have to use java.util.UUID. a default bridge for UUID would be nice... the code would be simple..

Absolutely, that would be nice to add. I think it's not there as nobody asked for it and we didn't think about it :)
Would you like to create a patch? We'll include it in the next release.

This is a starting point: http://community.jboss.org/wiki/Contrib ... nateSearch
but of course if you need help you can ask here, on the mailing list or on IRC as documented http://hibernate.org/community

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Programmatic API document id bridge
PostPosted: Thu Oct 06, 2011 9:50 am 
Newbie

Joined: Wed Oct 05, 2011 12:33 pm
Posts: 4
thanks for the quick reply.

I will have a go at creating the patch.

The code does not work, I can not seem to find a way to add a field bridge to a document Id.

cheers,
Greg B.


Top
 Profile  
 
 Post subject: Re: Programmatic API document id bridge
PostPosted: Thu Oct 06, 2011 5:33 pm 
Newbie

Joined: Wed Oct 05, 2011 12:33 pm
Posts: 4
ok I have made the changes and added test cases in-line with what was already done.

I have a small issue tho, I can not get all test cases to pass when using Maven. They seem to run fine in eclipse.

It seems that when test cases are storing an index on the file system they fail.. I am developing on windows.. most of them are passing.


an example
org.hibernate.search.SearchException: Unable to create index directory: C:\Users\g_beauchamp\git\hibernate-search\hibernate-search-orm\file:\C:\Users\g_beauchamp\git\hibernate-search\hibernate-search-engine\target\indextemp\AsyncBackendLongWorklistsStressTest.testWorkLongerThanMaxQueueSize for index org.hibernate.search.test.Clock


Results :

Tests in error:
testBoost(org.hibernate.search.test.FSDirectoryTest): HSEARCH000103: Unable to initialize IndexManager Documents
testEventIntegration(org.hibernate.search.test.FSDirectoryTest): HSEARCH000103: Unable to initialize IndexManager Documents
testSearchOnDeletedIndex(org.hibernate.search.test.FSDirectoryTest): HSEARCH000103: Unable to initialize IndexManager Documents
testWorkLongerThanMaxQueueSize(org.hibernate.search.test.backend.AsyncBackendLongWorklistsStressTest): HSEARCH000103: Unable to initialize IndexManager org.hibernate.search.test.Clock
testWorkLongerThanMaxQueueSize(org.hibernate.search.test.backend.SyncBackendLongWorklistsStressTest): HSEARCH000103: Unable to initialize IndexManager org.hibernate.search.test.Clock
testCorrectNumberOfShardsDetected(org.hibernate.search.test.configuration.ShardsConfigurationTest): HSEARCH000103: Unable to initialize IndexManager Book.0
testSelectionOfShardingStrategy(org.hibernate.search.test.configuration.ShardsConfigurationTest): HSEARCH000103: Unable to initialize IndexManager Book.0
testShardingSettingsInherited(org.hibernate.search.test.configuration.ShardsConfigurationTest): HSEARCH000103: Unable to initialize IndexManager Book.0
testShardN2UsesDefaults(org.hibernate.search.test.configuration.ShardsConfigurationTest): HSEARCH000103: Unable to initialize IndexManager Book.0
testShardN1_ExplicitParams(org.hibernate.search.test.configuration.ShardsConfigurationTest): HSEARCH000103: Unable to initialize IndexManager Book.0
testMMapDirectoryType(org.hibernate.search.test.directoryProvider.FSDirectorySelectionTest): HSEARCH000103: Unable to initialize IndexManager org.hibernate.search.test.directoryProvider.SnowStorm
testNIODirectoryType(org.hibernate.search.test.directoryProvider.FSDirectorySelectionTest): HSEARCH000103: Unable to initialize IndexManager org.hibernate.search.test.directoryProvider.SnowStorm
testSimpleDirectoryType(org.hibernate.search.test.directoryProvider.FSDirectorySelectionTest): HSEARCH000103: Unable to initialize IndexManager org.hibernate.search.test.directoryProvider.SnowStorm
testProperCopy(org.hibernate.search.test.directoryProvider.FSSlaveAndMasterDPTest): Unable to setup test directories
testSourceNotReady(org.hibernate.search.test.directoryProvider.FSSlaveAndMasterDPTest): Unable to setup test directories
testStandardInitialization(org.hibernate.search.test.directoryProvider.RetryInitializeTest): Unable to setup test directories
testStandardInitialization(org.hibernate.search.test.directoryProvider.RetryInitializeTest)
testInitiallyFailing(org.hibernate.search.test.directoryProvider.RetryInitializeTest): Unable to setup test directories
testInitiallyFailing(org.hibernate.search.test.directoryProvider.RetryInitializeTest)
testMasterDelayedInitialization(org.hibernate.search.test.directoryProvider.RetryInitializeTest): Unable to setup test directories
testMasterDelayedInitialization(org.hibernate.search.test.directoryProvider.RetryInitializeTest)
testJGroupsBackend(org.hibernate.search.test.jgroups.common.JGroupsCommonTest): HSEARCH000103: Unable to initialize IndexManager org.hibernate.search.test.jgroups.master.TShirt
testIndexCtrlMBeanRegistered(org.hibernate.search.test.jmx.IndexControlMBeanTest): java.lang.IllegalArgumentException: java.io.File parameter must be a directory. [C:\Users\g_beauchamp\git\hibernate-search\hibernate-search-orm\file:\C:\Users\g_beauchamp\git\hibernate-search\hibernate-search-engine\target\simpleJndi]
testAttributesAndOperations(org.hibernate.search.test.jmx.IndexControlMBeanTest): java.lang.IllegalArgumentException: java.io.File parameter must be a directory. [C:\Users\g_beauchamp\git\hibernate-search\hibernate-search-orm\file:\C:\Users\g_beauchamp\git\hibernate-search\hibernate-search-engine\target\simpleJndi]
testIndexAndPurge(org.hibernate.search.test.jmx.IndexControlMBeanTest): java.lang.IllegalArgumentException: java.io.File parameter must be a directory. [C:\Users\g_beauchamp\git\hibernate-search\hibernate-search-orm\file:\C:\Users\g_beauchamp\git\hibernate-search\hibernate-search-engine\target\simpleJndi]
testMBeanNotRegisteredWithoutExplicitProperty(org.hibernate.search.test.jmx.NoMBeansEnabledTest): java.lang.IllegalArgumentException: java.io.File parameter must be a directory. [C:\Users\g_beauchamp\git\hibernate-search\hibernate-search-orm\file:\C:\Users\g_beauchamp\git\hibernate-search\hibernate-search-engine\target\simpleJndi]
testMultipleEntitiesPerIndex(org.hibernate.search.test.reader.nrtreaders.BasicNRTFunctionalityTest): HSEARCH000103: Unable to initialize IndexManager Documents
experimentWithAvro(org.hibernate.search.test.serialization.AvroTest)
testOptimize(org.hibernate.search.test.session.OptimizeTest): HSEARCH000103: Unable to initialize IndexManager org.hibernate.search.test.session.Email
testIdShardingStrategy(org.hibernate.search.test.shards.ShardsTest): HSEARCH000103: Unable to initialize IndexManager Animal.0
testBehavior(org.hibernate.search.test.shards.ShardsTest): HSEARCH000103: Unable to initialize IndexManager Animal.0
testInternalSharding(org.hibernate.search.test.shards.ShardsTest): HSEARCH000103: Unable to initialize IndexManager Animal.0


Top
 Profile  
 
 Post subject: Re: Programmatic API document id bridge
PostPosted: Fri Oct 07, 2011 8:54 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi,
you're right there is an issue with paths under Windows. Sorry we didn't spot that as nobody on the team is using Windows but we'll get that fixed as soon as possible.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Programmatic API document id bridge
PostPosted: Fri Oct 07, 2011 2:55 pm 
Newbie

Joined: Wed Oct 05, 2011 12:33 pm
Posts: 4
have tested the change, do I tag my changes or something so they can be picked up?


Top
 Profile  
 
 Post subject: Re: Programmatic API document id bridge
PostPosted: Sat Oct 08, 2011 4:29 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi,
first step is you should create a issue on JIRA so that we track this as a new feature: https://hibernate.onjira.com/browse/HSEARCH

To send the code changes you can either attach a traditional patch file to the issue in JIRA, or if you're familiar with git and github you can send a pull request.
Sending a pull request is preferable ;)

Last step (first time only) is to sign the contributor agreement:
please create an account on jboss.org if you don't have one and sign https://cla.jboss.org/ for the project "Hibernate". sorry for the bureaucracy, but it's just a short agreement and a checkbox it won't take you long.

then if you like you could subscribe to the developers mailing list http://hibernate.org/community/mailinglists and introduce yourself.

thank you!

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Programmatic API document id bridge
PostPosted: Mon Nov 21, 2011 6:34 am 
Newbie

Joined: Sat Nov 19, 2011 11:19 am
Posts: 4
Hi, I have a similar problem. Have you found a solution to create a document id bridge for the programmatic mapping? Thanks


Top
 Profile  
 
 Post subject: Re: Programmatic API document id bridge
PostPosted: Mon Nov 21, 2011 8:28 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Quote:
Hi, I have a similar problem. Have you found a solution to create a document id bridge for the programmatic mapping? Thanks

Hi, what is your problem? Could you post an example or create a testcase? I don't think it's the same issue, as the UUID patch was integrated.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Programmatic API document id bridge
PostPosted: Mon Nov 21, 2011 9:10 am 
Newbie

Joined: Sat Nov 19, 2011 11:19 am
Posts: 4
Hi, in my case I am trying to implement a problematic mapping for a entity. The entity has an an composite primary key annotated with @EmbeddedId.

Code:
...
@Entity(name = "a")
@Table(name = "a")
public class A implements java.io.Serializable {

...   

@EmbeddedId
   @AttributeOverrides( {
         @AttributeOverride(name = "name_1", column = @Column(name = "name_1", nullable = false, length = 64)),
         @AttributeOverride(name = "name_2", column = @Column(name = "name_2", nullable = false, length = 16)) })
   public AId getId() {
      return this.id;

...
   }


I try the same code, but the code does not work:

Code:
mapping.entity(A.class).indexed().indexName("a")
.property("id", ElementType.METHOD).documentId().field().bridge(ABridge.class)


Exception occurred during event dispatching:
org.hibernate.HibernateException: could not init listeners
...
Caused by: org.hibernate.search.SearchException: Unable to guess FieldBridge for id
...


I need an advise to solve my problem. Thanks


Top
 Profile  
 
 Post subject: Re: Programmatic API document id bridge
PostPosted: Mon Nov 21, 2011 9:55 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
locking this topic, follow up is here: https://forum.hibernate.org/viewtopic.php?f=9&t=1013437

_________________
Sanne
http://in.relation.to/


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.