OGM version: 5.0.0.Beta1
Cassandra version: 2.2.5
One of the data types I have for an attribute in the Cassandra keyspace entity I am trying to retrieve data from is a DECIMAL, having had a look around it seems it is recommended that for this type, the java equivalent should be BigDecimal, therefore I used this for this particular attribute in my table POJO and recieved:
Exception in thread "main" java.lang.ClassCastException: java.math.BigDecimal cannot be cast to java.lang.String at org.hibernate.ogm.type.descriptor.impl.StringMappedGridExtractor.extract(StringMappedGridExtractor.java:32)
at org.hibernate.ogm.type.impl.AbstractGenericBasicType.nullSafeGet(AbstractGenericBasicType.java:220)
at org.hibernate.ogm.type.impl.AbstractGenericBasicType.nullSafeGet(AbstractGenericBasicType.java:216)
at org.hibernate.ogm.type.impl.AbstractGenericBasicType.nullSafeGet(AbstractGenericBasicType.java:207)
at org.hibernate.ogm.type.impl.AbstractGenericBasicType.hydrate(AbstractGenericBasicType.java:296)
at org.hibernate.ogm.persister.impl.OgmEntityPersister.hydrateValue(OgmEntityPersister.java:996)
at org.hibernate.ogm.persister.impl.OgmEntityPersister.hydrate(OgmEntityPersister.java:941)
at org.hibernate.ogm.loader.impl.OgmLoader.loadFromResultSet(OgmLoader.java:1157)
at org.hibernate.ogm.loader.impl.OgmLoader.instanceNotYetLoaded(OgmLoader.java:1064)
at org.hibernate.ogm.loader.impl.OgmLoader.getRow(OgmLoader.java:958)
at org.hibernate.ogm.loader.impl.OgmLoader.getRowFromResultSet(OgmLoader.java:497)
at org.hibernate.ogm.loader.impl.OgmLoader.doQuery(OgmLoader.java:372)
at org.hibernate.ogm.loader.impl.OgmLoader.doQueryAndInitializeNonLazyCollections(OgmLoader.java:282)
at org.hibernate.ogm.loader.impl.OgmLoader.loadEntity(OgmLoader.java:201)
at org.hibernate.ogm.loader.impl.OgmLoader.load(OgmLoader.java:157)
at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3955)
at org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:491)
at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:456)
at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:199)
at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:261)
at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:137)
at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1129)
at org.hibernate.internal.SessionImpl.access$2600(SessionImpl.java:164)
at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.load(SessionImpl.java:2696)
at org.hibernate.internal.SessionImpl.get(SessionImpl.java:975)
at org.hibernate.engine.spi.SessionDelegatorBaseImpl.get(SessionDelegatorBaseImpl.java:630)
Now I have tried replacing the BigDecimal to different types like long and double which causes an earlier datatype error, the method that I am calling upon execution is simply:
Code:
public class Main_v2 {
public static void main(String[] args) {
//v1
OgmSession ss = HibernateUtil_v1.openOgmSFSession();
Transaction trans = ss.beginTransaction();
long id = 2370256;
MediaEntity media = ss.get(MediaEntity.class, id);
trans.commit();
System.out.println("Capture Device: " + media.getLatitude());
System.out.println("Date Uploaded: " + media.getUploadDate());
//v1
//ss.close();
HibernateUtil_v1.closeOgmSessionFactory();
}
}
The MediaEntity POJO with the declared BigDecimal datatype:
Code:
@Entity
@Table(name = "media")
public class MediaEntity implements Serializable{
private long mediaID;
private BigDecimal latitude;
private Date uploadDate;
public MediaEntity() {}
@Id
@Column(name = "media_id", nullable = false)
public long getMediaID() {
return mediaID;
}
public void setMediaID(long mediaID) {
this.mediaID = mediaID;
}
@Column(name = "latitude")
public BigDecimal getLatitude() {
return latitude;
}
public void setLatitude(BigDecimal latitude) {
this.latitude = latitude;
}
@Column(name = "date_uploaded")
public Date getUploadDate() {
return uploadDate;
}
public void setUploadDate(Date uploadDate) {
this.uploadDate = uploadDate;
}
}
I'm not converting it to a string myself therefore it must be some background process the OGM framework does, but for some reason this error occurs. The value that I would be expecting to get from Cassandra for this specific media is 54.3. Any ideas folks?
Cheers :>