-->
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.  [ 12 posts ] 
Author Message
 Post subject: hibernate search inheritance changed?
PostPosted: Mon Dec 15, 2008 7:17 pm 
Newbie

Joined: Mon Dec 15, 2008 6:49 pm
Posts: 3
I have a question on how to map a subclasses which have an abstract base class.

I was doing it by having all classes marked as @Indexed and they were all put in the same index, named for the base class.

But when I upgraded to Hibernate Search 3.1.0.GA I got the following warnings:

14:39:56,164 WARN [SearchFactoryImpl] Abstract classes can never insert index documents. Remove @Indexed.

14:39:56,164 WARN [DocumentBuilderContainedEntity] @DocumentId specified on an entity which is not indexed by itself. Annotation gets ignored. Use @Field instead.

I then removed @Indexed from the base class, and then it put each sub-class in its own index. But I still get the second warning, since the documentId is in the abstract base class. So what is the correct way to do this?

And why is there no mention of this change (or any mention of inheritance at all) in the online docs?

Thanks,
Mark


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 16, 2008 5:33 am 
Newbie

Joined: Wed Nov 12, 2008 5:31 am
Posts: 7
I have played with the new version of hibernate search (3.1) a little and as i understand, you dont have to mark the abstract base classes as indexed now instead of it just mark all the subclasses as indexed. So you will have one folder for every indexed class.
To the second warning in your case: have you removed @DocumentId annotation in your abstract class? I would say you dont need it anymore.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 16, 2008 1:29 pm 
Newbie

Joined: Mon Dec 15, 2008 6:49 pm
Posts: 3
Yes, I tried removing the @DocumentId annotation, and it didn't work - it hung on startup. I should mention that I'm not using annotations for the hibernate mapping, so how else would it know the id?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 16, 2008 5:34 pm 
Newbie

Joined: Wed Nov 12, 2008 5:31 am
Posts: 7
According to the official documentation you have to use @DocumentID until you dont mark your entity id with the @ID hibernate annotation. On the other side there should not be a problem in using of the hibernate xml mappings and hibernate search. Unfortunately i have no idea what would be the right solution for your case.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 31, 2008 5:47 pm 
Newbie

Joined: Mon Dec 15, 2008 6:49 pm
Posts: 3
Does anybody know? This must be a common situation.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 07, 2009 6:19 am 
Beginner
Beginner

Joined: Fri Sep 26, 2008 2:39 am
Posts: 20
Quote:
Quote:
Yes, I tried removing the @DocumentId annotation, and it didn't work - it hung on startup.


this is a serious problem - i am having it too.

If I remove @DocumentID annotation from the abstract class I get a hang-up situation too.

No Error, No Exception - my jboss just hangs and i have to shut down the java-vm.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 07, 2009 7:40 am 
Hibernate Team
Hibernate Team

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

it could just be a case of a bad log message, but it could also be a bug. I will have to look at the code and create a test case. It would help if you could post some example code.

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 07, 2009 9:27 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Looking at the code you should be able to just ignore the second warning. I created a Jira issue (http://opensource.atlassian.com/projects/hibernate/browse/HSEARCH-333 for removing or improving the message.

Let me know if there are any other problems.

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 07, 2009 1:15 pm 
Beginner
Beginner

Joined: Fri Sep 26, 2008 2:39 am
Posts: 20
So this would be a correct hibernate-search usage?

---
abstract class BaseClass
@DocumentID
long id;

<getter, setter, some other stuff for the application>
---

and then (multiple cases) of:

---
@Indexed
class SomeClass extends BaseClass

@Field
String something;

<getter, setter, more stuff>
---


I thinks that's the essence of what i am doing right now, and with the new hibernate-search version i got the warning about @DocumentID in abstract class.

Or is there an error in my approach/my thinking?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 08, 2009 5:55 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
That's should work just fine. As said, the warning message is misleading and there is a Jira issue for it now.

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 08, 2009 2:08 pm 
Beginner
Beginner

Joined: Fri Sep 26, 2008 2:39 am
Posts: 20
thanks (again and again *g*)


Top
 Profile  
 
 Post subject: Re: hibernate search inheritance changed?
PostPosted: Tue Oct 27, 2009 12:13 pm 
Newbie

Joined: Tue Oct 27, 2009 12:02 pm
Posts: 2
I'm having a similar problem with hibernate-search and inheritance.

This is the class diagram and annotations.


@Entity
@Indexed
@Inheritance
@DiscriminatorColumn(name="thirdType")
public abstract class Third implements Serializable {

@DocumentId
private Long id;

@Field(index=Index.TOKENIZED, store=Store.YES)
private String identificationCardNumber;

@OneToMany
@IndexedEmbedded(depth=100)
@JoinTable(
name="ThirdAddresses",
joinColumns = @JoinColumn( name="thirdId"),
inverseJoinColumns = @JoinColumn( name="addressId")
)
@Cascade({CascadeType.SAVE_UPDATE ,CascadeType.DELETE_ORPHAN})
@LazyCollection(LazyCollectionOption.FALSE)
private Set<Address> addresses;

public Third() {}

.......................


Third has a set of addresses and Address is an abstract class (defined below). Also, Third has children like ThirdPhysical.............

@Entity
@Indexed
@DiscriminatorValue("Physical")
public class ThirdPhysical extends Third implements Serializable {

@Field(index=Index.TOKENIZED, store=Store.YES)
private String name;

@Field(index=Index.TOKENIZED, store=Store.YES)
private String surname;


public ThirdPhysical() {
}

........................


Address is an abstract class like Third


@Entity
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
@DiscriminatorColumn(name="addressType")
@Embeddable
public abstract class Address implements Serializable {

@Id
@DocumentId
@GeneratedValue(strategy = GenerationType.TABLE)
@Column(name = "addressId")
private Long id;

private boolean preference;

public Address() {}
.......................................


Address has children like EmailAddress ..........


@Entity
@DiscriminatorValue("Email")
@Indexed
public class EmailAddress extends Address implements Serializable {

@Field(index=Index.TOKENIZED, store=Store.YES)
private String email;

private Boolean notification;

public EmailAddress() { }

....................................



The problem is that the index is only for the Third attributes and the id attribute of the Address class. There's no indexation for emailAddress .....


Do you have any idea??

Thanks in advance


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