-->
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.  [ 2 posts ] 
Author Message
 Post subject: Problem with OneToOne mapping and hibernate search
PostPosted: Fri Oct 19, 2007 1:38 am 
Newbie

Joined: Thu Oct 18, 2007 7:09 am
Posts: 1
I'm having a problem with bi-directional OneToOne mapping and searching from association mapped by @IndexedEmbedded. Seems that search returns all rows from database but only those rows that have identifier matched the search. But those elements not matching the search have null identifier. When session.load(id) is tried for those elements exception is thrown.

Roughly I have following mapping :
Code:
@Entity
@Indexed
public class Place {
    @Id
    @GeneratedValue
    @DocumentId
    private Long id;

    @Field
    private String name;

    @OneToOne(fetch = FetchType.LAZY, mappedBy = "place")
    @IndexedEmbedded
    private Address address;
    ....
}

@Entity
@Indexed
public class Address {
    @Id
    @GeneratedValue
    @DocumentId
    private Long id;

    @Field
    private String street;

    @Field
    private String city;

    @OneToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="place_f_id")
    @ContainedIn
    private Place place;
    ...
}


When I execute following query

Code:
MultiFieldQueryParser parser = new MultiFieldQueryParser(
              new String[]{ "address.street" },
              new StandardAnalyzer());

        Query query = null;
      try {
         query = parser.parse(search);
      } catch (ParseException e) {
         throw new RuntimeException(e.getLocalizedMessage());
      }
        org.hibernate.Query hibQuery = fullTextSession.createFullTextQuery(query, Place.class);
       
        List<Place> result = hibQuery.list();


I will get following error
Code:
java.lang.IllegalArgumentException: id to load is required for loading
   at org.hibernate.event.LoadEvent.<init>(LoadEvent.java:51)
   at org.hibernate.event.LoadEvent.<init>(LoadEvent.java:33)
   at org.hibernate.impl.SessionImpl.load(SessionImpl.java:792)
   at org.hibernate.impl.SessionImpl.load(SessionImpl.java:788)
   at org.hibernate.search.engine.QueryLoader.load(QueryLoader.java:84)
   at org.hibernate.search.query.FullTextQueryImpl.list(FullTextQueryImpl.java:244)



Error happens in the query loader which received all database rows but only those rows that matched the search have identifiers.
When this code is executed in the QueryLoader
Code:
for (EntityInfo entityInfo : entityInfos) {
         Object element = session.load( entityInfo.clazz, entityInfo.id );
         if ( Hibernate.isInitialized( element ) ) {
            //all existing elements should have been loaded by the query,
            //the other ones are missing ones
            result.add( element );
         }
      }


session.load will of course throw this exception when trying to fetch object with null identifier.

Am I missing something in the set up or in the query or is this bug in hibernate search? I can fix this in the QueryLoader by checking for null values but I don't know if it will cause side effects.

Thanks for your help.


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

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
You can do that as a temporary hack, but can you also open a JIRA issue with a running test case (ie data creation then query), I cannot reproduce what you see. The id loaded from the Lucene index should never be null

_________________
Emmanuel


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