-->
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.  [ 1 post ] 
Author Message
 Post subject: Hibernate Search Cast problem
PostPosted: Fri Sep 24, 2010 10:18 am 
Newbie

Joined: Fri Sep 03, 2010 4:14 am
Posts: 3
Hi,
We have two tables Assay and Project and one Project has many assays.
The schema is given below.

Schema for Assay_Test (Assay)
PRIMARY_KEY NUMBER(10,0)
COLLECTION_KEY NUMBER(10,0)
ASSAY_NAME VARCHAR2(4000 BYTE)
PROJECT_ID_FK VARCHAR2(4000 BYTE)



Schema for Project_Test (Project)
PRIMARY_KEY NUMBER(10,0)
COLLECTION_KEY NUMBER(10,0)
PROJECT_NAME VARCHAR2(4000 BYTE)

The relationship between Assay and Project is between 'PROJECT_ID_FK' of Assay and 'COLLECTION_KEY' of Project.Using Hibernate session with Annotations ,I assigned @DocumentID annotation to 'PRIMARY_KEY' of Assay and Project because it is unique.
After this configuration when i run the program and try to fetch the list of Assays using Project object, I get the following error.

Message:com.entities.ProjectTest cannot be cast to java.math.BigDecimal
java.lang.ClassCastException: com.entities.ProjectTest cannot be cast to java.math.BigDecimal
at org.hibernate.type.BigDecimalType.getHashCode(BigDecimalType.java:71)
at org.hibernate.type.AbstractType.getHashCode(AbstractType.java:144)
at org.hibernate.engine.EntityKey.generateHashCode(EntityKey.java:126)
at org.hibernate.engine.EntityKey.<init>(EntityKey.java:70)
at org.hibernate.engine.StatefulPersistenceContext.getCollectionOwner(StatefulPersistenceContext.java:733)
at org.hibernate.loader.Loader.readCollectionElement(Loader.java:1037)
at org.hibernate.loader.Loader.readCollectionElements(Loader.java:690)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:630)
at org.hibernate.loader.Loader.doQuery(Loader.java:745)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:270)
at org.hibernate.loader.Loader.loadCollection(Loader.java:2062)
at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:62)
at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:628)
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:83)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1853)
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:369)
at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:111)
at org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:186)
at Main.search2(Main.java:133)
at Main.main(Main.java:48)

The error occurs at the following code snippet
Set<AssayTest> list=project.getAssayTests();
for (AssayTest assay:list){
System.out.println("assay name from project" +assay.getAssayName());


}

If i change the @DocumentID to 'COLLECTION_KEY' of Project, the error vanishes and program runs fine.However i can't make 'Collection_KEY' as @DocumentID because it is not unique for data in our production server.Only Primary_key is unique.
so is there any restriction in Hibernate Search that you have to annotate @DocumentID to an attribute that has been used in specifying relationship between the entities.Is there any workaround this limitation?.
Any help or comments would be appreciated.
Thanks,
Ali

Here is the Assay_Test Entity

/**
* The persistent class for the ASSAY_TEST database table.
*
*/
@Indexed
@Entity
@Table(name="ASSAY_TEST")
public class AssayTest implements Serializable {
private static final long serialVersionUID = 1L;
@Field
@Column(name="ASSAY_NAME", length=4000)
private String assayName;
@Field
@Column(name="COLLECTION_KEY", precision=10)
private BigDecimal collectionKey;
@Id
@DocumentId
@Field
@Column(name="PRIMARY_KEY", precision=10)
private BigDecimal primaryKey;

//bi-directional many-to-one association to ProjectTest
@NotFound(action=NotFoundAction.IGNORE)
@ManyToOne
@JoinColumn(name="PROJECT_ID_FK", referencedColumnName="COLLECTION_KEY")
private ProjectTest projectTest;

public AssayTest() {
}

public String getAssayName() {
return this.assayName;
}

public void setAssayName(String assayName) {
this.assayName = assayName;
}

public BigDecimal getCollectionKey() {
return this.collectionKey;
}

public void setCollectionKey(BigDecimal collectionKey) {
this.collectionKey = collectionKey;
}

public BigDecimal getPrimaryKey() {
return this.primaryKey;
}

public void setPrimaryKey(BigDecimal primaryKey) {
this.primaryKey = primaryKey;
}

public ProjectTest getProjectTest() {
return this.projectTest;
}

public void setProjectTest(ProjectTest projectTest) {
this.projectTest = projectTest;
}

}

Here is the Project_Test Entity

package com.entities;

/**
* The persistent class for the PROJECT_TEST database table.
*
*/
@Indexed
@Entity
@Table(name="PROJECT_TEST")
public class ProjectTest implements Serializable {
private static final long serialVersionUID = 1L;

@Id
@DocumentId
@Field
@Column(name="PRIMARY_KEY", precision=10)
private BigDecimal primaryKey;
@Field
@Column(name="PROJECT_NAME", length=4000)
private String projectName;

@Field
@Column(name="COLLECTION_KEY")
private String collectionKey;
//bi-directional many-to-one association to AssayTest
@NotFound(action=NotFoundAction.IGNORE)
@OneToMany(mappedBy="projectTest")
private Set<AssayTest> assayTests;

public ProjectTest() {
}

public BigDecimal getPrimaryKey() {
return this.primaryKey;
}

public void setPrimaryKey(BigDecimal primaryKey) {
this.primaryKey = primaryKey;
}

public String getProjectName() {
return this.projectName;
}

public void setProjectName(String projectName) {
this.projectName = projectName;
}

public Set<AssayTest> getAssayTests() {
return this.assayTests;
}

public void setAssayTests(Set<AssayTest> assayTests) {
this.assayTests = assayTests;
}

public void setCollectionKey(String collectionKey) {
this.collectionKey = collectionKey;
}

public String getCollectionKey() {
return collectionKey;
}

}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.