-->
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: Double lucene documents when inserting
PostPosted: Thu Oct 04, 2007 3:53 am 
Pro
Pro

Joined: Wed Oct 03, 2007 2:31 pm
Posts: 205
Hi

I have started to use Hibernate search and I have encountered a problem. I have the following domain objects which i want to be able to search:
Contact
Phone
Address

Contact has a set of addresses and a set of phone numbers which i have mapped using Hibernate annotations. When doing an insert i have found that there is one lucene document in the index for Contact (which is correct as i am creating one contact with one address and phone object). The problem is that there are two lucene documents for Address and for Phone. Looking at the logs it seems as though hibernate is inserting address and phone twice and as a result the objects are being indexed twice.

I am not sure if anyone has encountered this problem or not. I am using Spring's hibernate template to do the inserting of data.

The following provides snippets of code:

Contact.java

@ContainedIn
@OneToMany(targetEntity=Address.class, cascade = {CascadeType.ALL}, fetch=FetchType.LAZY)
private Set<Address> addresses

@ContainedIn
@OneToMany(targetEntity=Phone.class, cascade = {CascadeType.ALL}, fetch=FetchType.LAZY)
private Set<Phone> phoneNumbers


Phone.java
@ManyToOne
@JoinColumn(name="CONTACT_ID")
@IndexedEmbedded
private Contact contact


Address.java
@ManyToOne
@JoinColumn(name="CONTACT_ID")
@IndexedEmbedded
private Contact contact

I would be grateful if some one would be able to assist on this problem


Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 04, 2007 9:40 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
You will have to give more info (tx / all the mapping / the code that actually do the job, the code that let ou believe the index has twice the same document). I have never seen such a problem, unless the object is also inserted twice in the DB.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 04, 2007 2:32 pm 
Pro
Pro

Joined: Wed Oct 03, 2007 2:31 pm
Posts: 205
Here are some of the info that you requested:

Spring session factory configuration:

Code:

<bean id="fullTextIndexEventListener"  class="org.hibernate.search.event.FullTextIndexEventListener" />

   <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
      <property name="dataSource">
         <ref local="dataSource" />
      </property>
        <property name="annotatedPackages">
           <list>
           </list>
        </property>
        <property name="annotatedClasses">
           <list>
              <value>com.amin.phonebook.domain.Address</value>
              <value>com.amin.phonebook.domain.Contact</value>
              <value>com.amin.phonebook.domain.Phone</value>
              <value>com.amin.phonebook.domain.PersonalContact</value>
              <value>com.amin.phonebook.domain.BusinessContact</value>
           </list>
        </property>
      <property name="eventListeners">
         <map>
            <entry>
             <key><value>post-update</value></key>
                <ref bean="fullTextIndexEventListener"/>
             </entry>
             <entry>
             <key><value>post-insert</value></key>
               <ref bean="fullTextIndexEventListener"/>
             </entry>
             <entry>
             <key><value>post-delete</value></key>
               <ref bean="fullTextIndexEventListener"/>
             </entry>
         </map>
      </property>
      <property name="hibernateProperties">
         <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</prop>
            <prop key="hibernate.hbm2ddl.auto">update</prop>
            <prop key="hibernate.search.default.directory_provider">org.hibernate.search.store.FSDirectoryProvider</prop>
            <prop key="hibernate.search.default.indexBase">/Users/amin/lucene/baseIndex</prop>
         </props>
      </property>
   </bean>



Dao code that creates a contact is :

Code:
public Contact createContact(Contact contact) {
      hibernateTemplate.save(contact);
      return contact;
   }



When inserting i get the following log statement:
Code:
2007-10-04 17:50:31,748 [org.hibernate.search.backend.impl.lucene.LuceneWorker] DEBUG - add to Lucene index: class com.amin.phonebook.domain.PersonalContact#1: Document<stored/uncompressed,indexed<_hibernate_class:com.amin.phonebook.domain.PersonalContact> stored/uncompressed,indexed<id:1> stored/uncompressed,indexed,tokenized<email:mail@mail.com> stored/uncompressed,indexed,tokenized<firstname:XXX> stored/uncompressed,indexed,tokenized<surname:XXXX>> - 18271
2007-10-04 17:50:31,923 [org.hibernate.search.backend.impl.lucene.LuceneWorker] DEBUG - remove from Lucene index: class com.amin.phonebook.domain.Address#0 - 18446
2007-10-04 17:50:31,944 [org.hibernate.search.backend.impl.lucene.LuceneWorker] DEBUG - add to Lucene index: class com.amin.phonebook.domain.Address#0: Document<stored/uncompressed,indexed<_hibernate_class:com.amin.phonebook.domain.Address> stored/uncompressed,indexed<id:0> stored/uncompressed,indexed,tokenized<address1:23423423> stored/uncompressed,indexed,tokenized<address2:N/A> stored/uncompressed,indexed,tokenized<town:Hove> stored/uncompressed,indexed,tokenized<county:East Sussex> stored/uncompressed,indexed,tokenized<country:United Kingdom> stored/uncompressed,indexed,tokenized<postcode:34234234> stored/uncompressed,indexed<contact.id:1> stored/uncompressed,indexed,tokenized<contact.email:mail.com>> - 18467
2007-10-04 17:50:32,339 [org.hibernate.search.backend.impl.lucene.LuceneWorker] DEBUG - remove from Lucene index: class com.amin.phonebook.domain.Phone#0 - 18862
2007-10-04 17:50:32,344 [org.hibernate.search.backend.impl.lucene.LuceneWorker] DEBUG - add to Lucene index: class com.amin.phonebook.domain.Phone#0: Document<stored/uncompressed,indexed<_hibernate_class:com.amin.phonebook.domain.Phone> stored/uncompressed,indexed<id:0> stored/uncompressed,indexed,tokenized<number:340239843209> stored/uncompressed,indexed,tokenized<type:HOME> stored/uncompressed,indexed<contact.id:1> stored/uncompressed,indexed,tokenized<contact.email:mail@mail.com>> - 18867


After which it inserts the address and phone and creates an index again for both. for example:
Code:
2007-10-04 17:50:32,775 [org.hibernate.engine.Cascade] DEBUG - cascade ACTION_SAVE_UPDATE for collection: com.amin.phonebook.domain.Contact.addresses - 19298
2007-10-04 17:50:32,775 [org.hibernate.engine.CascadingAction] DEBUG - cascading to saveOrUpdate: com.amin.phonebook.domain.Address - 19298
2007-10-04 17:50:32,779 [org.hibernate.engine.IdentifierValue] DEBUG - id unsaved-value: 0 - 19302
2007-10-04 17:50:32,780 [org.hibernate.event.def.AbstractSaveEventListener] DEBUG - transient instance of: com.amin.phonebook.domain.Address - 19303
2007-10-04 17:50:32,781 [org.hibernate.event.def.DefaultSaveOrUpdateEventListener] DEBUG - saving transient instance - 19304
2007-10-04 17:50:32,782 [org.hibernate.event.def.AbstractSaveEventListener] DEBUG - saving [com.amin.phonebook.domain.Address#<null>] - 19305
2007-10-04 17:50:32,782 [org.hibernate.event.def.AbstractSaveEventListener] DEBUG - executing insertions - 19305
2007-10-04 17:50:32,784 [org.hibernate.event.def.AbstractSaveEventListener] DEBUG - executing identity-insert immediately - 19307
2007-10-04 17:50:32,784 [org.hibernate.persister.entity.AbstractEntityPersister] DEBUG - Inserting entity: com.amin.phonebook.domain.Address (native id) - 19307
2007-10-04 17:50:32,785 [org.hibernate.jdbc.AbstractBatcher] DEBUG - about to open PreparedStatement (open PreparedStatements: 0, globally: 0) - 19308
2007-10-04
2007-10-04 17:50:32,806 [org.hibernate.search.backend.impl.lucene.LuceneWorker] DEBUG - add to Lucene index: class com.amin.phonebook.domain.Address#1: Document<stored/uncompressed,indexed<_hibernate_class:com.amin.phonebook.domain.Address> stored/uncompressed,indexed<id:1> stored/uncompressed,indexed,tokenized<address1:XXXX> stored/uncompressed,indexed,tokenized<address2:N/A> stored/uncompressed,indexed,tokenized<town:Hove> stored/uncompressed,indexed,tokenized<county:East Sussex> stored/uncompressed,indexed,tokenized<country:United Kingdom> stored/uncompressed,indexed,tokenized<postcode:BN3444> stored/uncompressed,indexed<contact.id:1> stored/uncompressed,indexed,tokenized<contact.email:XXXX>> - 19329


Hope this is enough info.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 04, 2007 2:32 pm 
Pro
Pro

Joined: Wed Oct 03, 2007 2:31 pm
Posts: 205
P.S Data is inserted once


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 06, 2007 12:26 pm 
Pro
Pro

Joined: Wed Oct 03, 2007 2:31 pm
Posts: 205
Hi

Any ideas...?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 09, 2007 6:19 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Sorry I thought I answered this one.
I might have an idea but I need to confirm. Can you open a JIRA issue, with the entities attached as well as the code that populate them and persist them.
I don't need the spring config thing, it is at least 4 times longer than what's needed :)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 10, 2007 3:05 pm 
Pro
Pro

Joined: Wed Oct 03, 2007 2:31 pm
Posts: 205
Will do. Thanks. Out of curiosity what do you think may be the problem?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 11, 2007 9:49 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
This might be due to @IndexedEmbedded handled before the associated object has its id set. Hence HSearch considers those as 2 different objects.
I find it surprising but I need to check.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 13, 2007 6:13 am 
Pro
Pro

Joined: Wed Oct 03, 2007 2:31 pm
Posts: 205
Hi

Thanks for your reply. I will raise the JIRA but i just wanted to show you how i am creating and address and phone. The entities are the same as i wrote in earlier posts:
I am running this code in a main method
Code:
Address address = new Address();
      address.setAddress1("TEST1");
      address.setAddress2("N/A");
      address.setTown("TEST TOWN");
      address.setCounty("TEST COUNTY");
      address.setCountry("UK");
      address.setPostcode("XXXXXXX");
      address.setActive(true);
      address.setCreatedOn(new Date());
      address.setLastUpdatedOn(new Date());

      Phone phone = new Phone();
      phone.setNumber("01273234122");
      phone.setType("HOME");
      phone.setCreatedOn(new Date());
      phone.setLastUpdatedOn(new Date());

      PersonalContact contact = new PersonalContact();
      contact.setFirstname("Amin");
      contact.setSurname("Mohammed-Coleman");
      contact.setEmail("address@hotmail.com");
      contact.setDateOfBirth(new Date());
      contact.setNotifyBirthDay(false);
      contact.setCreatedOn(new Date());
      contact.setLastUpdatedOn(new Date());
      contact.setNotes("TEST");
      contact.addAddressToContact(address);
      contact.addPhoneToContact(phone);

      ApplicationContext appCtx = new ClassPathXmlApplicationContext(new String[]{"/spring/context-dao.xml"});

      ContactDao contactDao = (ContactDao)appCtx.getBean("contactDao");
      contactDao.createContact(contact);
      List<Contact> contacts = contactDao.search("address@hotmail.com");
      System.out.println("contacts = " + contacts);



Just thought this might show something...probably not!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 19, 2007 8:37 am 
Pro
Pro

Joined: Wed Oct 03, 2007 2:31 pm
Posts: 205
Posted JIRA:
http://opensource.atlassian.com/project ... SEARCH-124

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 19, 2007 11:55 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Thank you

_________________
Emmanuel


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.