-->
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.  [ 5 posts ] 
Author Message
 Post subject: [Hibernate Search] Embedded id get indexed - design or bug?
PostPosted: Mon Oct 22, 2007 7:22 am 
Newbie

Joined: Mon Oct 22, 2007 7:04 am
Posts: 19
A typical pattern is to use an EntityBase mapped superclass for all entities in the application. In this class the id-handling (i.e. the primary key) is defined for all entities as well as some common utilities such as ... toString etc.

Suppose we have two entities called Foo and Bar, both inheriting from EntityBase, and that there exists a 1-many-relation from Foo to Bar, i.e. "Foo has Bars".

Suppose we want to index Foo with hibernate search. This we do by annotating the Foo class with @Indexed. We also add a @DocumentId on the id in EntityBase. Now we add a @Field to all fields in Foo we like to have in the index. By examining with luke all seems fine up to this point.

Now, when using @IndexEmbedded on the relation to Bar and adding a desired field in Bar to the same index we also ... unfortunately gets the id for the Bar entity indexed. This as a consequence of having the @DocumentId in the mapped superclass.

Is this the correct behavior really? I never added a @Indexed to Bar. I am just reaching it via "embedded" ... so I can't see why an inherited @DocumentId would at all matter in the embedded class.

Bug or by design?

/Tobias

I realize that I of course can work around this by breaking my pattern and override the id in Foo ... also moving down the @DocumentId to Foo. But it would be nice if I didn't have to.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 23, 2007 2:37 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
It is by designed, since @DocumentId really means 2 things: it's the id and it is @Field(UNTOKENIZED, STORE.YES)

Is that much of a problem to have the data indexed?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 23, 2007 3:52 pm 
Newbie

Joined: Mon Oct 22, 2007 7:04 am
Posts: 19
Hi Emmanuel,

No it is not much of a problem since I can work around it. It was a bit unexpected though why I thought this discussion (with your answer) could shed some light on it.

Actually the situation is a bit more complex than I described in the simplified example. We have several entities that are reached via relations whose DocumentIDs now are added to the index. We already have a very big index why anything stored in it not carrying information (that we really need) just seemed like a waste.

But as I said, no problem.

Best regards,
Tobias


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 23, 2007 3:59 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Note that the idea of having a technical superclass to handle common entity needs is more of an anti-pattern than a pattern specifically because of such issues.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 25, 2007 2:19 pm 
Newbie

Joined: Mon Oct 22, 2007 7:04 am
Posts: 19
Thanks for your feedback! I hear you. Superclass-antipattern soon gone.


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