-->
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: Hibernate-Search: IdClass composite pk
PostPosted: Tue Oct 09, 2012 4:58 am 
Newbie

Joined: Tue Oct 09, 2012 4:46 am
Posts: 1
I've configurated with hibernate-search annotation (4.1.1 version library) my class Intervento. So, I'm using jpa and in my case i can omit @DocumentId but I have a composite primary key...

Code:
@IdClass(it.domain.InterventoPK.class)
@Entity
@Indexed
@AnalyzerDef(name = "interventongram", tokenizer = @TokenizerDef(factory = StandardTokenizerFactory.class),
filters = {
    @TokenFilterDef(factory = LowerCaseFilterFactory.class),
    @TokenFilterDef(factory = StopFilterFactory.class, params = {
       @Parameter(name = "words", value = "lucene/dictionary/stopwords.txt"),
       @Parameter(name = "ignoreCase", value = "true"),
       @Parameter(name = "enablePositionIncrements", value = "true")
    }),
    @TokenFilterDef(factory = ItalianLightStemFilterFactory.class),
    @TokenFilterDef(factory = SynonymFilterFactory.class, params = {
       @Parameter(name = "synonyms", value = "lucene/dictionary/synonyms.txt"),
       @Parameter(name = "expand", value = "true")
    }),
    @TokenFilterDef(factory = SnowballPorterFilterFactory.class, params = {
         @Parameter(name = "language", value = "Italian")
    })
})
@Table(name = "intervento", catalog = "gestionale")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(namespace = "Clinigo/it/domain", name = "Intervento")
@XmlRootElement(namespace = "Clinigo/it/domain")
public class Intervento implements Serializable {
   private static final long serialVersionUID = 1L;

   /**
    */
   
   @Column(name = "idintervento", nullable = false)
   @Basic(fetch = FetchType.EAGER)
   @Id
   @XmlElement
   Integer idintervento;
   /**
    */

   @Column(name = "lingua_idlingua", nullable = false)
   @Basic(fetch = FetchType.EAGER)
   @Id
   @XmlElement
   Integer linguaIdlingua;
   /**
    */
   @Temporal(TemporalType.TIMESTAMP)
   @Column(name = "version", nullable = false)
   @Basic(fetch = FetchType.EAGER)
   @XmlElement
   Calendar version;

...


I'm getting....can you help me?

ERROR: HSEARCH000058: HSEARCH000116: Unexpected error during MassIndexer operation
java.lang.ClassCastException: it.domain.InterventoPK cannot be cast to java.lang.Integer
at org.hibernate.type.descriptor.java.IntegerTypeDescriptor.unwrap(IntegerTypeDescriptor.java:36)
at org.hibernate.type.descriptor.sql.IntegerTypeDescriptor$1.doBind(IntegerTypeDescriptor.java:57)
at org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:92)
at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:305)
at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:300)
at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1891)
at org.hibernate.loader.Loader.bindParameterValues(Loader.java:1862)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1737)
at org.hibernate.loader.Loader.doQuery(Loader.java:828)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:289)
at org.hibernate.loader.Loader.doList(Loader.java:2447)
at org.hibernate.loader.Loader.doList(Loader.java:2433)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2263)
at org.hibernate.loader.Loader.list(Loader.java:2258)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:122)
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1535)
at org.hibernate.internal.CriteriaImpl.list(CriteriaImpl.java:374)
at org.hibernate.search.batchindexing.impl.IdentifierConsumerEntityProducer.loadList(IdentifierConsumerEntityProducer.java:150)
at org.hibernate.search.batchindexing.impl.IdentifierConsumerEntityProducer.loadAllFromQueue(IdentifierConsumerEntityProducer.java:117)
at org.hibernate.search.batchindexing.impl.IdentifierConsumerEntityProducer.run(IdentifierConsumerEntityProducer.java:94)
at org.hibernate.search.batchindexing.impl.OptionallyWrapInJTATransaction.run(OptionallyWrapInJTATransaction.java:84)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)


Top
 Profile  
 
 Post subject: Re: Hibernate-Search: IdClass composite pk
PostPosted: Tue Oct 09, 2012 5:13 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi Flavio,

IdClass is not handled automatically, Hibernate Search can't access the id type with this mapping. We can try improve on this, can you please open an issue on JIRA?
https://hibernate.onjira.com/browse/HSEARCH

You can change your mapping slightly to make it work: don't use the IdClass combined with two @Id fields, but use the mapping style having a single @Id element on a field of type InterventoPK and mark this as embeddable.

For an example see:
5.1.2.1.1. id as a property using a component type

in http://docs.jboss.org/hibernate/core/4.1/manual/en-US/html_single/

Then on the Id field you can define a TwoWayFieldBridge to define how you want this field to be indexed.

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


Top
 Profile  
 
 Post subject: Re: Hibernate-Search: IdClass composite pk
PostPosted: Tue Oct 09, 2012 9:12 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
An alternative to changing your mapping is that you add add a @DocumentId on some getter, and return any object - maybe even a string - which is a unique composite of the two ids components.

When using JPA you can avoid specifying the @DocumentId but you don't have to, you can still use the annotation to override the definition of indentity to apply on the index mapping.

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


Top
 Profile  
 
 Post subject: Re: Hibernate-Search: IdClass composite pk
PostPosted: Fri Nov 07, 2014 1:55 am 
Newbie

Joined: Fri Nov 07, 2014 1:02 am
Posts: 1
Hi Sanne,
I am trying to work with composite key with hibernate search as you suggested(I have thousands of exiting code).I have created a method to convert composite key to a unique string as given below(like we do in TwoWayFieldBridge). I have annotated a method with @DocumentId as given below. Storing objects is fine. But If I search a entity,Hibernate search tries to assign value to a field which is not existing. In the below case Hibernate tries to set key value to "documentId". If I had a setter to reassign the field companyId and userId it was great, But how can tell hibernarte to call a setDocumentId() ,such that I can recover the composite keys.
Code:
@IdClass(UserId.class)
public class User{
@Id
private int companyId;
@Id
private int userId;
@DocumentId
     public String getDocumentId(){
      return companyId+"|"+userId;
     }
}

public class UserId implements Serializable{
private int companyId;
private int userId;
}


Thanks...


Top
 Profile  
 
 Post subject: Re: Hibernate-Search: IdClass composite pk
PostPosted: Fri Nov 07, 2014 6:57 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi,
I'm surprised, I think I did similar mappings in the past but I need to look it up as I forgot the details. It's possible that what I did doesn't work anymore, or best case it's an important missing point in the documentation.

I've created an issue to track this:
https://hibernate.atlassian.net/browse/HSEARCH-1715

We'll have a look soon, if you find the trick in the meantime please let me know :)

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


Top
 Profile  
 
 Post subject: Re: Hibernate-Search: IdClass composite pk
PostPosted: Wed Oct 19, 2016 3:13 am 
Newbie

Joined: Tue Oct 18, 2016 5:06 am
Posts: 1
Hello,

I have the same problem... I want to integrate Hibernate Search in existing project with hundreds of entities but at least half of entities use @IdClass annotation as composed key.
Can I solve the problem using the annotation @IdClass?

I have the following example:

entity class:
Code:
@Entity
@Table(name="FAKVS_DB")
@IdClass(value=PK_FAKVS_DB.class)
@Audited
@Indexed
public class FAKVS_DB implements Serializable {

   @Id
   @Column(name="Key_FAM", length=10, nullable=false)l
   private String keyFam;
   
   @Id
   @Column(name="Komponentennr", nullable=false)
   private Integer komponentenNr;
   
   @Id
   @Column(name="Hinweis", nullable=true, length=4)
   private String hinweis;

        //getters and setters
}


and composed key:

Code:
public class PK_FAKVS_DB implements Serializable {

   private String keyFam;
   private Integer komponentenNr;
   private String hinweis;

        //getters and setters
}


If I can not use @IdClass annotation can you tell me what are the alternatives?

Thank you very much in advance.


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.