-->
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.  [ 21 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: No index update although @IndexedEmbedded & @ContainedIn
PostPosted: Mon Aug 03, 2009 8:56 am 
Newbie

Joined: Tue Jul 14, 2009 6:13 am
Posts: 12
Hi,
my problem occurs on updating an AttributeValue as this doesn't trigger an index update. :( I have a complicated model in my application. For this reason I am using the IndexEmbedded-Annotation in my Product-Class to keep some attributes for that Product. And in the Attribute.class I am using IndexEmbedded for indexing different AttributeValue's for that Attribute.
Everything works fine in my application if I only insert or delete products. But if I update an AttributeValue the change is made persistent in the database, but the lucene-index isn't updated although I use @ContainedIn to build bidirectional relationships.

So why isn't my index kept up to date in this case? Does anybody have an idea?



Here the concrete code. I have the following classes in my Application with some Annotations:
I have a product with a Collection of Attributes:
Code:
@IdClass(ProductPK.class) @Entity(name = "product") @Table(name = "product")
@Indexed @Analyzer(impl = GermanAnalyzer.class)
public class Product extends AbstractProduct<Product, ProductPK> {
   @OneToMany(mappedBy = "product", fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.REMOVE })
   @IndexedEmbedded
   private Collection<Attribute> attributes;
...


the Attribute.class looks like:
Code:
@Entity(name="productAttribute") @Table(name="product_attribute")
@org.hibernate.annotations.Table(indexes={@Index(name="nameIndex", columnNames={"name"})}, appliesTo = "product_attribute")
public class Attribute extends AbstractAttribute<Attribute> {
   @ManyToOne
   @ContainedIn
   private Product product;

    @OneToMany(mappedBy="attribute", fetch=FetchType.LAZY, cascade={CascadeType.PERSIST,CascadeType.REMOVE})
    @OrderBy("order asc")
    @IndexedEmbedded
   private List<AttributeValue> values;
...


The AttributeValue.class looks like:
Code:
@Entity(name="attributeValue")
@Table(name="product_attribute_value")
public class AttributeValue extends AbstractAttributeValue<AttributeValue> {
   @ManyToOne(targetEntity=Attribute.class, fetch=FetchType.EAGER)
   @ContainedIn
   private Attribute attribute;
...


And the superclass of AttributeValue: AbstractAttributeValue.class looks like:
Code:
@MappedSuperclass
public abstract class AbstractAttributeValue<T extends AbstractChangeableEntity<T, Integer>>
      extends AbstractChangeableEntity<T, Integer> {
   @Column(name = "_value")
   @Field(index = Index.TOKENIZED, store = Store.YES)
   private String value;
...


and last but not least the code which I want to use to update an AttributeValue. perhaps my mistake is already here but I don't see it.
Code:
      EntityManagerFactory emf = Persistence
            .createEntityManagerFactory("lof");
      EntityManager em = emf.createEntityManager();
      em.getTransaction().begin();

      String variante = "Variante 123 xyz";
      Query q = em
            .createQuery("select p from product p where p.variante=:variante");
      q.setParameter("variante", variante);
      q.setMaxResults(1);
      Product p = null;
      try {
         p = (Product) q.getResultList().get(0);
         System.out.println(p.getId());
      } catch (NoResultException e) {
         System.out.println("No entity found for query");
         System.exit(0);
      }

      Attribute kommentarAttribut = null;
      Collection<Attribute> attributes = p.getAttributes();
      for (Iterator iterator = attributes.iterator(); iterator.hasNext();) {
         Attribute attribute = (Attribute) iterator.next();
         if (attribute.getName().equals("Kommentar")) {
            kommentarAttribut = attribute;
            break;
         }
      }

      List<AttributeValue> values = kommentarAttribut.getValues();
      for (Iterator iterator = values.iterator(); iterator.hasNext();) {
         AttributeValue attributeValue = (AttributeValue) iterator.next();
         System.out.println(attributeValue.getValue());
         attributeValue
               .setValue(new Date()
                     + " changing the AttributeValue");
      }

      em.merge(p);
      em.getTransaction().commit();
      em.close();


Last edited by InteroStrubbl on Tue Nov 10, 2009 9:32 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: No index update although @IndexEmbedded & @ContainedIn
PostPosted: Mon Aug 03, 2009 10:22 am 
Newbie

Joined: Wed Jul 15, 2009 12:34 pm
Posts: 18
What if you try to index the Attribute class too, putting the @Indexed annotation in this class? I know that you're not interested in indexing the Attributes but I think it might solve your problem.


Top
 Profile  
 
 Post subject: Re: No index update although @IndexEmbedded & @ContainedIn
PostPosted: Mon Aug 03, 2009 10:37 am 
Newbie

Joined: Tue Jul 14, 2009 6:13 am
Posts: 12
YES :) thank you very much.

it solved the problem! but can you explain why I have to put @Indexed to the Attribute class, too? (although I'll never intend to search for an Attribute)


Top
 Profile  
 
 Post subject: Re: No index update although @IndexEmbedded & @ContainedIn
PostPosted: Mon Aug 03, 2009 1:57 pm 
Newbie

Joined: Wed Jul 15, 2009 12:34 pm
Posts: 18
I still don't know the reasons for that. I just noticed that indexing the "intermediate class" would solve the problem when I faced a example like yours that used a two-level embedding of objects.


Top
 Profile  
 
 Post subject: Re: No index update although @IndexEmbedded & @ContainedIn
PostPosted: Wed Aug 05, 2009 2:23 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
interesting!
please open a JIRA, I think it's supposed to work as you meant in the first post: IMHO it should be considered to be fixed.

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


Top
 Profile  
 
 Post subject: Re: No index update although @IndexEmbedded & @ContainedIn
PostPosted: Fri Sep 18, 2009 12:27 am 
Beginner
Beginner

Joined: Wed Nov 10, 2004 5:48 pm
Posts: 32
Location: Portland
Just a quick ping - I'm having the same (or at least related) problem:

A -> @IndexedEmbedded -> B (no indexed fields) -> @IndexedEmbedded -> C (two indexed fields)

Both relationships have @IndexedEmbedded on the 'owning' side and @ContainedIn on the 'owned' side.

When I add A, it is indexed but the fields from C are not.
If I update A later, the fields from C get picked up at that time.

It may be worth noting that C is an abstract class? I doubt it though - until recently there was no 'B'; it just went from A-> @IndexedEmbedded -> C and it worked fine until I added the intermediate level. I've checked via Luke and confirmed that it isn't indexed on add.

The workaround of @Indexed on B did not work for me.


Top
 Profile  
 
 Post subject: Re: No index update although @IndexEmbedded & @ContainedIn
PostPosted: Fri Sep 18, 2009 3:59 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
thanks for the additional information.
Here is the issue, for reference: http://opensource.atlassian.com/projects/hibernate/browse/HSEARCH-391

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


Top
 Profile  
 
 Post subject: Re: No index update although @IndexEmbedded & @ContainedIn
PostPosted: Thu Sep 24, 2009 6:47 am 
Pro
Pro

Joined: Wed Oct 03, 2007 2:31 pm
Posts: 205
Hi
We are experiencing the same problem. According to the JIRA is has been resolved. Is there a patch or is there any info on which version it has been fixed in? We are using 3.1.1.GA

Cheers
Amin


Top
 Profile  
 
 Post subject: Re: No index update although @IndexEmbedded & @ContainedIn
PostPosted: Thu Sep 24, 2009 5:24 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hello,
Hardy solved this on trunk, you can create a patch from the public SVN repository using "svn diff".
The resulting patch should be easily adaptable to the source code of 3.1.1

I'll propose this to be backported as it appears to be quite popular ;-)

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


Top
 Profile  
 
 Post subject: Re: No index update although @IndexEmbedded & @ContainedIn
PostPosted: Fri Sep 25, 2009 3:20 am 
Pro
Pro

Joined: Wed Oct 03, 2007 2:31 pm
Posts: 205
s.grinovero wrote:
Hello,
Hardy solved this on trunk, you can create a patch from the public SVN repository using "svn diff".
The resulting patch should be easily adaptable to the source code of 3.1.1

I'll propose this to be backported as it appears to be quite popular ;-)


Thanks for your reply. Is there a timeframe for when this will be backported? I'll have a go at creating the patch but me and SVN have a flaky relationship.


Top
 Profile  
 
 Post subject: Re: No index update although @IndexEmbedded & @ContainedIn
PostPosted: Fri Sep 25, 2009 11:25 am 
Pro
Pro

Joined: Wed Oct 03, 2007 2:31 pm
Posts: 205
svn hates me. I have tried creating a patch but it seems that the two versions are quite different and I am unalbe to see what should and should not be adapted. Is there any possibility that I could get the patch from you (modified) and then I can apply to branch 3.1.1 and build from my end.

Thanks in advance.


Top
 Profile  
 
 Post subject: Re: No index update although @IndexEmbedded & @ContainedIn
PostPosted: Fri Sep 25, 2009 1:17 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi, I'll help you out tomorrow.. sorry I can't get to a computer today

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


Top
 Profile  
 
 Post subject: Re: No index update although @IndexEmbedded & @ContainedIn
PostPosted: Sun Sep 27, 2009 7:06 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
You can find a backported patch as attachment of the issue : http://opensource.atlassian.com/projects/hibernate/browse/HSEARCH-391

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


Top
 Profile  
 
 Post subject: Re: No index update although @IndexEmbedded & @ContainedIn
PostPosted: Sun Sep 27, 2009 8:42 am 
Pro
Pro

Joined: Wed Oct 03, 2007 2:31 pm
Posts: 205
Excellent thanks! I will apply patch when at work. long day today and now i've got to dismantle our chicken house and apply red mite treatment.


Top
 Profile  
 
 Post subject: Re: No index update although @IndexEmbedded & @ContainedIn
PostPosted: Sun Sep 27, 2009 8:50 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
FYI I committed the changes on the 3_1 branch too, in case you prefer to check out the full source tree.

_________________
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.  [ 21 posts ]  Go to page 1, 2  Next

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.