-->
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.  [ 2 posts ] 
Author Message
 Post subject: java.math.BigDecimal cannot be cast to java.lang.String OGM5
PostPosted: Fri Apr 08, 2016 5:58 pm 
Newbie

Joined: Thu Apr 07, 2016 8:39 am
Posts: 3
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 :>


Top
 Profile  
 
 Post subject: Re: java.math.BigDecimal cannot be cast to java.lang.String OGM5
PostPosted: Mon Apr 11, 2016 7:06 am 
Hibernate Team
Hibernate Team

Joined: Fri Sep 09, 2011 3:18 am
Posts: 295
Hi,
Hibernate OGM at the moment stores BigDecimal as text, I've created an issue for it and sent a pull request:

If you could test it and let us know if it solves you issue, that would be great.

Thanks,
Davide


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