-->
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.  [ 6 posts ] 
Author Message
 Post subject: GenerationType.SEQUENCE @Indexed
PostPosted: Mon Feb 04, 2008 12:06 pm 
Beginner
Beginner

Joined: Thu Jun 07, 2007 2:38 am
Posts: 28
Location: Italy, Rome
My class looks something like this:

Code:
@Indexed
public abstract class Resource {

   @Id
   @GeneratedValue(strategy = GenerationType.SEQUENCE)
   Long resourceId;


Using GenerationType.SEQUENCE causes objects not to be found via hibernate search.

What can I do to make these objects found by Hibernate Search?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 04, 2008 4:13 pm 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Why do you think that GenerationType.SEQUENCE is the problem. I am using a sequence generator for ids and it just works fine. In many databases it is even the default. Does it work without GenerationType.SEQUENCE?

Maybe you could provide some more details regarding your problem.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 05, 2008 6:49 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
First of all your mapping is missing @DocumentId :)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 06, 2008 6:14 am 
Beginner
Beginner

Joined: Thu Jun 07, 2007 2:38 am
Posts: 28
Location: Italy, Rome
Thanks for thinking with me!

Code sample 1: works
Code:
@Entity
@MappedSuperclass
@Indexed
public abstract class Resource implements VisitableResource {

//   @DocumentId
   @Id
//   @GeneratedValue(strategy = GenerationType.SEQUENCE)
   @GeneratedValue
   Long resourceId;

Code sample 2: Hibernate search does not find the object
Code:
@Entity
@MappedSuperclass
@Indexed
public abstract class Resource implements VisitableResource {

//   @DocumentId
   @Id
   @GeneratedValue(strategy = GenerationType.SEQUENCE)
//   @GeneratedValue
   Long resourceId;

Code sample 3: Caused by: org.hibernate.annotations.common.AssertionFailure: Two document id assigned: resourceId and resourceId
Code:
@Entity
@MappedSuperclass
@Indexed
public abstract class Resource implements VisitableResource {

   @DocumentId
   @Id
   @GeneratedValue(strategy = GenerationType.SEQUENCE)
//   @GeneratedValue
   Long resourceId;



I would love to do Code sample 3 but I don't understand the error ( Two document id assigned).

I am using HSQL and use as much as possible the JPA annotations(for instance javax.persistence.Id).

Any ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 06, 2008 10:13 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
show all the code including the superclass VisitableResource.

PS having @MappedSuperclass and @Entity on the same bean does not make sense.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 07, 2008 6:13 am 
Beginner
Beginner

Joined: Thu Jun 07, 2007 2:38 am
Posts: 28
Location: Italy, Rome
This is the full code:

Code:
package org.fao.fenix.domain;

import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;

import org.hibernate.search.annotations.DocumentId;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Index;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.Store;

@Entity
@MappedSuperclass
@Indexed
public abstract class Resource implements VisitableResource {

   @Id
   @GeneratedValue(strategy = GenerationType.SEQUENCE)
   Long resourceId;

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

   String abstractAbstract;

   String[] keywords;

   // Organization provider;
   // Organization source;
   // Contact contact;
   Date startDate;
   Date dateLastUpdate;

   /**
    * Validity period of the data. Valid values are Day, Week, Month and Year.
    * The validity period starts from dateLastUpdate.
    */
   String periodTypeCode;

   /**
    * Is this Public and Protected?
    *
    */
   String sharingCode;

   @Field(index = Index.TOKENIZED, store = Store.YES)
   public String getPeriodTypeCode() {
      return periodTypeCode;
   }

   public void setPeriodTypeCode(String periodTypeCode) {
      this.periodTypeCode = periodTypeCode;
   }

   @Field(index = Index.TOKENIZED, store = Store.YES)
   public String getSharingCode() {
      return sharingCode;
   }

   public void setSharingCode(String sharingCode) {
      this.sharingCode = sharingCode;
   }

   @DocumentId
   public Long getResourceId() {
      return resourceId;
   }

   public void setResourceId(Long resourceId) {
      this.resourceId = resourceId;
   }

   @Field(index = Index.TOKENIZED, store = Store.YES)
   public String getTitle() {
      return title;
   }

   public void setTitle(String title) {
      this.title = title;
   }

   @Field(index = Index.TOKENIZED, store = Store.YES)
   public String getAbstractAbstract() {
      return abstractAbstract;
   }

   public void setAbstractAbstract(String abstractAbstract) {
      this.abstractAbstract = abstractAbstract;
   }

   public String[] getKeywords() {
      return keywords;
   }

   public void setKeywords(String[] keywords) {
      this.keywords = keywords;
   }

   @Field(index = Index.TOKENIZED, store = Store.YES)
   public Date getStartDate() {
      return startDate;
   }

   public void setStartDate(Date startDate) {
      this.startDate = startDate;
   }

   @Field(index = Index.TOKENIZED, store = Store.YES)
   public Date getDateLastUpdate() {
      return dateLastUpdate;
   }

   public void setDateLastUpdate(Date dateLastUpdate) {
      this.dateLastUpdate = dateLastUpdate;
   }

}



Code:
package org.fao.fenix.domain;

/**
*
*/
public interface VisitableResource {
   public void accept(ResourceVisitor resourceVisitor);
}




About what you said: having @MappedSuperclass and @Entity on the same bean does not make sense
We have Resource as an attribute to User:
Code:
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
private List<Resource> resources = new ArrayList<Resource>();

Hibernate complains when Resource is not an entity and therefore I added @Entity. I agree with you that it makes no sense but I did not know another solution. Do you have a suggestion?


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