Bad value for type long in postgres

Viewed 41

I am having a java application with Pojo being

 public class ArtifactBlobs{
    private static final long serialVersionUID = 1L;
    private String guid;
    private String workspaceId;
    private Blob artifactBlobValue;
    private Date createdAt;
    private Long createdBy;
    private Date updatedAt;
    private Long updatedBy;
    private Set waasArtifactsBlobsMetas = new HashSet(0);

    public ArtifactsBlobs() {
    }

    public ArtifactsBlobs(String guid, Date createdAt, Date updatedAt) {
        this.guid = guid;
        this.createdAt = createdAt;
        this.updatedAt = updatedAt;
    }

    public ArtifactsBlobs(String guid, String workspaceId,
            Blob artifactBlobValue, Date createdAt, Long createdBy,
            Date updatedAt, Long updatedBy) {
        this.guid = guid;
        this.workspaceId = workspaceId;
        this.artifactBlobValue = artifactBlobValue;
        this.createdAt = createdAt;
        this.createdBy = createdBy;
        this.updatedAt = updatedAt;
        this.updatedBy = updatedBy;
    }

    public String getGuid() {
        return this.guid;
    }

    public void setGuid(String guid) {
        this.guid = guid;
    }

    public String getWorkspaceId() {
        return this.workspaceId;
    }

    public void setWorkspaceId(String workspaceId) {
        this.workspaceId = workspaceId;
    }

    public Blob getArtifactBlobValue() {
        return this.artifactBlobValue;
    }

    @SuppressWarnings("CPD-START")
    public void setArtifactBlobValue(Blob artifactBlobValue) {
        this.artifactBlobValue = artifactBlobValue;
    }

    public Date getCreatedAt() {
        return this.createdAt;
    }

    public void setCreatedAt(Date createdAt) {
        this.createdAt = createdAt;
    }

    public Long getCreatedBy() {
        return this.createdBy;
    }

    public void setCreatedBy(Long createdBy) {
        this.createdBy = createdBy;
    }

    public Date getUpdatedAt() {
        return this.updatedAt;
    }

    public void setUpdatedAt(Date updatedAt) {
        this.updatedAt = updatedAt;
    }

    public Long getUpdatedBy() {
        return this.updatedBy;
    }

    public void setUpdatedBy(Long updatedBy) {
        this.updatedBy = updatedBy;
    }

    public Set getWaasArtifactsBlobsMetas() {
        return this.waasArtifactsBlobsMetas;
    }

    public void setWaasArtifactsBlobsMetas(Set waasArtifactsBlobsMetas) {
        this.waasArtifactsBlobsMetas = waasArtifactsBlobsMetas;
    }
                     }

Exactly this method was failing

private ArtifactsBlobs 
        getArtifactBlobById(
            String workspaceId,
            String blobId) 
    {
public static final String GET_ARTIFACT_BLOB_BY_ID = "from ArtifactsBlobs A where A.guid = :blobId and A.workspaceId = :workspaceId";
        Map<String, Object> valuesMap = new HashMap<>();
        valuesMap.put("workspaceId", workspaceId);
        valuesMap.put("blobId", blobId);
        ArtifactsBlobs artifactBlob = 
            iGenericDAO.getEntity(
                SqlQuery.GET_ARTIFACT_BLOB_BY_ID,
                valuesMap);
        
        if (artifactBlob == null) 
        {
            // Since the blobId is derived from data stored in artifacts table, 
            // absence of corr. entry in blobs table indicates data is incorrect in DB
            throw new DataIntegrityViolationException(
                "An unexpected error has occured while processing the request. Please try again later.");
        }
        
        return artifactBlob;
    }

And the hibernate bean configuration being

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<!-- Generated 23 Sep, 2014 12:10:11 PM by Hibernate Tools 3.4.0.CR1 -->
    <hibernate-mapping>
        <class name="com.db.entity.autogen.ArtifactsBlobs" table="artifacts_blobs">
            <id name="guid" type="string">
                <column name="id" length="36" />
                <generator class="assigned" />
            </id>
            <property name="workspaceId" type="string">
                <column name="workspace_id" length="36" />
            </property>
            <property name="artifactBlobValue" type="blob">
                <column name="artifact_blob_value" not-null="true"/>
            </property>
            <property name="createdAt" type="timestamp">
                <column name="created_at" length="19" not-null="true" />
            </property>
            <property name="createdBy" type="java.lang.Long">
                <column name="created_by" />
            </property>
            <property name="updatedAt" type="timestamp">
                <column name="updated_at" length="19" not-null="true" />
            </property>
            <property name="updatedBy" type="java.lang.Long">
                <column name="updated_by" />
            </property>
            <set name="waasArtifactsBlobsMetas" table="waas_artifacts_blobs_meta" inverse="true" lazy="true" fetch="select">
                <key>
                    <column name="blob_id" length="36" not-null="true" />
                </key>
                <one-to-many class="com.kony.waas.db.entity.autogen.WaasArtifactsBlobsMeta" />
            </set>
        </class>
    </hibernate-mapping>

and the Db Structure is 

    CREATE TABLE artifacts_blobs (
      id varchar(36) NOT NULL,
      workspace_id varchar(36) NOT NULL,
      artifact_blob_value bytea NOT NULL,
      created_at timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP,
      created_by bigint NOT NULL,
      updated_at timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP,
      updated_by bigint NOT NULL,
      PRIMARY KEY (id)
    ) ;

The saving of the POJO class is going fine but while retrieving I am facing this error

javax.persistence.PersistenceException: org.hibernate.exception.DataException: could not execute query at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:154) ~[hibernate-core-5.3.20.Final.jar:5.3.20.Final] at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1575) ~[hibernate-core-5.3.20.Final.jar:5.3.20.Final] at org.hibernate.query.internal.AbstractProducedQuery.uniqueResult(AbstractProducedQuery.java:1608) ~[hibernate-core-5.3.20.Final.jar:5.3.20.Final]

Caused by: org.postgresql.util.PSQLException: Bad value for type long : \x35313162373838396435613932383937613638303266336663303236633964366332393838393638356663613039323163623538383562666164366163643039306633656335613162333734313638353539303335343662306336666164343232353362306261306 at org.postgresql.jdbc.PgResultSet.toLong(PgResultSet.java:3253) ~[postgresql-42.5.0.jar:42.5.0] at org.postgresql.jdbc.PgResultSet.getLong(PgResultSet.java:2436) ~[postgresql-42.5.0.jar:42.5.0] at org.postgresql.jdbc.PgResultSet.getBlob(PgResultSet.java:456) ~[postgresql-42.5.0.jar:42.5.0] at org.postgresql.jdbc.PgResultSet.getBlob(PgResultSet.java:442) ~[postgresql-42.5.0.jar:42.5.0]

0 Answers
Related