-->
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.  [ 14 posts ] 
Author Message
 Post subject: CollectionOfElements Indexing problem
PostPosted: Thu Feb 25, 2010 11:45 am 
Beginner
Beginner

Joined: Thu Feb 25, 2010 11:33 am
Posts: 36
I there,

I'm posting here because I'm just not finding where my problem is. I read the Hibernate search book'chapter 4 in every way but I didn't found anything...

So my problem is :

I've a class like this (this is not the real class but lightweighted for the example):

Code:
@Entity
@Indexed
public class BusinessUnit implements Serializable {
  // there are some fields but they are not realevant and ...
  @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "businessUnit")
  @CollectionOfElements
  @IndexedEmbedded
  private Collection<BuAddress> addresses = new HashSet<BuAddress>();
  // blablah
}

@Entity
@Embeddable
public class BuAddress implements Serializable {
  // there are some fields but they are not realevant and ...
  @Column(name = "ADR_RUE", length = 100)
  @Field(store = Store.YES)
  private String rue;
  // Some other fields ...
  @ManyToOne(fetch = FetchType.EAGER)
  @JoinColumn(name = "BUSINESS_UNIT_ID")
  @ContainedIn
  private BusinessUnit businessUnit;
}


When I'm persisting data, everything's fine. When I'm opening Luke ... I've the bad surprize that the Index is not set! I cannot see any addresses.rue ...

Any Idea?


Top
 Profile  
 
 Post subject: Re: CollectionOfElements Indexing problem
PostPosted: Fri Feb 26, 2010 10:43 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

basically it should work. In your case I am first of wondering about your mapping. If you use components and @CollectionOfElements, then @CollectionOfElements should be used as replacement of @OneToMany, not together as you do.

You also define @Entity and @Embeddable on BuAddress. That seems odd to me as well. Even though I am not sure whether this causes your problems I would start looking there.

Otherwise which version of Search are you using?

--Hardy


Top
 Profile  
 
 Post subject: Re: CollectionOfElements Indexing problem
PostPosted: Mon Mar 01, 2010 7:15 am 
Beginner
Beginner

Joined: Thu Feb 25, 2010 11:33 am
Posts: 36
hardy.ferentschik wrote:
If you use components and @CollectionOfElements, then @CollectionOfElements should be used as replacement of @OneToMany


Ok, but then I'm loosing my specific mappedBy = "businessUnit" information on the @OneToMany annotation ...
By the way, I tried to replace the annotation, but that doesn't change anything to my problem...

hardy.ferentschik wrote:
You also define @Entity and @Embeddable on BuAddress. That seems odd to me as well. Even though I am not sure whether this causes your problems I would start looking there.


@Entity is defined to say Hibernate that I will use the class for the persistence. If I remove that annotation, Hibernate will not generate the database and persistence anymore isn't it?
@Embeddable is written in the Hibernate Search in Action examples.
I've tried to replace @Embeddable with @Indexed, I've two separate indexes. (Not what I want)
I've also tried to remove @Embeddable but no index is created for that object ...

I'm still searching the issue but I'm not finding it ...


Top
 Profile  
 
 Post subject: Re: CollectionOfElements Indexing problem
PostPosted: Mon Mar 01, 2010 1:42 pm 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
@Embeddable and @CollectionOfElements are Hibernate Core specific annotations. They have nothing to do with Hibernate Search. And yes, if you just use @Embeddable you don't get a database table, because this annotation denotes what is called "components" in Hibernate Core. Embedded classes don't get their own table, but rather get additional columns in the containing classes.

If you are after standard one to many mapping (no components), remove @OneToMany and @Embeddable.
If indexing still does not work after this changes, let's have a look at your indexing code.

--Hardy


Top
 Profile  
 
 Post subject: Re: CollectionOfElements Indexing problem
PostPosted: Tue Mar 02, 2010 10:33 am 
Beginner
Beginner

Joined: Thu Feb 25, 2010 11:33 am
Posts: 36
My database is correctly genarated and is not my current problem.

My problem is that I want to make an embedded index of BuAddress in the index of my BusinessUnit. I've succeeded to do that with @ManyToOne relations on other objects, but whatever I do, it doesn't work for this @OneToMany relation.

My case is graphically described in the point 4.2.1 (page 105) of the Hibernate Search book, but I can't make that example alive ...

I do not want to embed my database tables in other tables, I just want to embed the Lucene Search Index of BuAddress into the index of the BusinessUnit.

Thanks!


Top
 Profile  
 
 Post subject: Re: CollectionOfElements Indexing problem
PostPosted: Tue Mar 02, 2010 2:27 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hardy was saying that your mapping is wrong: you can't use both @CollectionOfElements and @OneToMany, choose one; this mapping error you made was probably not showing up until you tested Search, but the problem is not Search dependent you have to fix the mapping first.

Hardy, WDYT about throwing an exception in case of such a mapping? it's inconsistent, should it be hard to at least log a warning? nevermind if it's complex to implement.

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


Top
 Profile  
 
 Post subject: Re: CollectionOfElements Indexing problem
PostPosted: Wed Mar 03, 2010 4:12 am 
Beginner
Beginner

Joined: Thu Feb 25, 2010 11:33 am
Posts: 36
Yes, I understood that well but modifying my code to remove the @OneToMany annotation for the @CollectionOfElements didn't change anything except that I loose my "MappedBy" information...

Hibernate is working well, I get all the informations I need.

I don't unterstand why you ask me to modify my mappings for a HibernateSearch problem as Hardy said that's nothing to do with hibernate searh ...


Last edited by romainvdk on Wed Mar 03, 2010 4:21 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: CollectionOfElements Indexing problem
PostPosted: Wed Mar 03, 2010 4:21 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
ok, sorry for misunderstanding I tought there was confusion on that.
Could you please show your fixed mapping so that we can try to reproduce the problem?

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


Top
 Profile  
 
 Post subject: Re: CollectionOfElements Indexing problem
PostPosted: Wed Mar 03, 2010 4:24 am 
Beginner
Beginner

Joined: Thu Feb 25, 2010 11:33 am
Posts: 36
Here is the modification I made :

Code:
    // @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "businessUnit")
@CollectionOfElements(fetch = FetchType.EAGER)
@IndexedEmbedded
private Collection<BuAddress> addresses = new HashSet<BuAddress>();


I didn't change anything other by now . Any Idea for the lost "MappedBy" information?


Top
 Profile  
 
 Post subject: Re: CollectionOfElements Indexing problem
PostPosted: Wed Mar 17, 2010 3:50 am 
Beginner
Beginner

Joined: Thu Feb 25, 2010 11:33 am
Posts: 36
Any Idea?


Top
 Profile  
 
 Post subject: Re: CollectionOfElements Indexing problem
PostPosted: Wed Mar 17, 2010 5:45 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
hi, sorry nearly forgot this.

could you post a minimal pair of entities having this problem? I assume now that you also removed the
Quote:
@ManyToOne(fetch = FetchType.EAGER)
as it doesn't make sense using embeddable components but it's hard to follow, especially as it works here I need the exact situation. I still am of the idea that your hibernate mapping might be wrong.

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


Top
 Profile  
 
 Post subject: Re: CollectionOfElements Indexing problem
PostPosted: Thu Mar 18, 2010 9:33 am 
Beginner
Beginner

Joined: Thu Feb 25, 2010 11:33 am
Posts: 36
Ok, here is the exact situation.
To make it shorter, I dropped every getters, setters, etc.

Here is my Business Unit Entity :
Code:
@Entity
@Indexed
public class BusinessUnit implements Serializable {

    private static final long serialVersionUID = 6381933189791412636L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(nullable = false, name = "BU_ID")
    private Integer id;
    @Column(name = "BU_ENNUMB", length = 100)
    private String entityNumber;
    @Column(name = "BU_MAIL", length = 200)
    private String email;
    @Column(name = "BU_WEB", length = 512)
    private String website;
    @Column(name = "BU_GSM", length = 20)
    private String gsm;
    @Column(name = "BU_TEL", length = 20)
    private String tel;
    @Column(name = "BU_FAX", length = 20)
    private String fax;
    @Column(name = "BU_VAL")
    private Boolean validity;
    @Column(name = "MODIFDATE")
    private Date modifyDate;
    @Column(name = "CREATIONDATE")
    private Date creationDate;
    // Associtations
    @OneToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "ARTINFO_ID")
    @Fetch(FetchMode.JOIN)
    @IndexedEmbedded
    private ArtisanInfo artisanInfo;
    // @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "businessUnit")
    @CollectionOfElements(fetch = FetchType.EAGER)
    @IndexedEmbedded
    private Collection<BuAddress> addresses = new HashSet<BuAddress>();
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "KBOENTR_ID")
    private KboEnterprise enterprise;
    @ManyToMany
    @JoinTable(name = "SELECTEDCAT", joinColumns = @JoinColumn(name = "BU_ID"), inverseJoinColumns =    @JoinColumn(name = "CAT_ID"))
    private Set<Categories> categories = new HashSet<Categories>();

    ...
}


And here is my BuAddress Entity:
Code:
@Entity
// @Indexed
public class BuAddress implements Serializable {

    private static final long serialVersionUID = -1145537123252752661L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(nullable = false, name = "ADR_ID")
    private Integer id;
    @Column(name = "ADR_LANG", length = 5)
    private String lang;
    @Column(name = "ADR_RUE", length = 100)
    @Field(store = Store.YES)
    private String rue;
    @Column(name = "ADR_NUM", length = 5)
    private String numero;
    @Column(name = "ADR_BTE", length = 5)
    private String boite;
    @Column(name = "ADR_CODE", length = 5)
    private String codepostal;
    @Column(name = "ADR_LOC", length = 5)
    @Field
    private String localite;
    @Column(name = "ADR_PAY", length = 5)
    private String pays;
    // Associations
    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "COMMUNE_ID")
    @Fetch(FetchMode.JOIN)
    @IndexedEmbedded
    private Commune commune;

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "BUSINESS_UNIT_ID")
    @ContainedIn
    private BusinessUnit businessUnit;
 
   ...

}


I left my comments for a better visibility.

You will see I make other IndexEmbedded in the BuAddress. Those are working fine if I remove the Index Embedded from the Business Unit. But I need to have all those indexes in my BusinessUnit Lucene's index ...

Romain.


Top
 Profile  
 
 Post subject: Re: CollectionOfElements Indexing problem
PostPosted: Wed Mar 24, 2010 6:29 am 
Beginner
Beginner

Joined: Thu Feb 25, 2010 11:33 am
Posts: 36
still no idea?


Top
 Profile  
 
 Post subject: Re: CollectionOfElements Indexing problem
PostPosted: Thu Mar 25, 2010 7:25 am 
Beginner
Beginner

Joined: Thu Feb 25, 2010 11:33 am
Posts: 36
I probably found the problem ...

it seems that the order in which we create elements is very important and I just swapped two creations and my code is now working.

Thanks for help!


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