[hibernate-issues] [Hibernate-JIRA] Commented: (HSEARCH-979) Programmatic API: mapping a composite primary key

Michael Heinrichs (JIRA) noreply at atlassian.com
Tue Mar 27 16:26:50 EDT 2012


    [ https://hibernate.onjira.com/browse/HSEARCH-979?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=46096#comment-46096 ] 

Michael Heinrichs commented on HSEARCH-979:
-------------------------------------------

I'm not using an EmbeddedId, but experience the same error: using the programmatic API to specify a TwoWayFieldBridge on a DocumentID does not work.  I think this is because the code assumes that the DocumentID field is a "NumericField".  I applied the following code change to version 3.6.2_FINAL, and it appears to work. Someone with more knowledge of the code could judge whether there are undesirable side effects (and probably provide a better way to get the DocumentID Field object).

{code:title=org.hibernate.search.engine.DocumentBuilderIndexedEntity.diff}
245a246,248
> 		org.hibernate.search.annotations.Fields fields = member.getAnnotation( org.hibernate.search.annotations.Fields.class );
> 		org.hibernate.search.annotations.Field[] fieldArray = (fields == null) ? null : fields.value();
> 		org.hibernate.search.annotations.Field fieldAnn = (fieldArray == null || fieldArray.length == 0) ? null : fieldArray[0];
258c261
< 				FieldBridge fieldBridge = BridgeFactory.guessType( null, numericFieldAnn, member, reflectionManager );
---
> 				FieldBridge fieldBridge = BridgeFactory.guessType( fieldAnn, numericFieldAnn, member, reflectionManager );
{code}

> Programmatic API: mapping a composite primary key
> -------------------------------------------------
>
>                 Key: HSEARCH-979
>                 URL: https://hibernate.onjira.com/browse/HSEARCH-979
>             Project: Hibernate Search
>          Issue Type: Bug
>          Components: mapping
>    Affects Versions: 3.3.0.Final, 3.4.1.Final
>         Environment: Hibernate 3.6 Final
>            Reporter: Fuessmann
>
> Hallo, I'm using Hibernate Search in combination with the [b]Programmatic API[/b] for dynamic indexing. Is there any possibility to index an entity with an composite primary key annotated with [b]@EmbeddedId[/b]. Using H.Search without the Programmatic API i choose a TwoWayFieldBridge but how can I use it with the Programmatic API?
> In my case I am trying to implement a programmatic mapping for an entity. The entity has an an composite primary key annotated with @EmbeddedId. 
> {quote}
> ...
> @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;
> ...
> 	}
> {quote}
> Code for ABridge.class is not shown but still exists ..
> I try a code like this, but the code does not work:
> {quote}
> mapping.entity(A.class).indexed().indexName("a")
> .property("id", ElementType.METHOD).documentId().field().bridge(ABridge.class)
> {quote}
> Exception occurred during event dispatching:
> {quote}
> org.hibernate.HibernateException: [color=#FF0000]could not init listeners{color} 
> ...
> Caused by: org.hibernate.search.SearchException: {color:red} Unable to guess FieldBridge for id{color} 
> ...
> {quote}
> I need an advise to solve my problem. Thanks

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list