0

Getting following error when trying to insert a new record into a table of PostgreSQL using Hibernate3

column "dml_script" is of type bytea but expression is of type bigint
  Hint: You will need to rewrite or cast the expression.
  Position: 187

Here is the mapping file:

import java.sql.Blob;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.Table;

@Entity
@Table(name="PMD14_DB_VERSION")
public class Dbversion {
    private Long identifier;
    private Long majorVersion;
    private Long minorVersion;
    private Long patchVersion;
    private Date dateExecuted;
    private String status;
    private Date dmlastupdate;
    private String userDetail;
    private Long dbapplicationfk;
    @Id
    @Column(name="ID")
    public Long getIdentifier() {
        return identifier;
    }
    public void setIdentifier(final Long identifier) {
        this.identifier = identifier;
    }

    @Column(name="DB_APPLICATION_FK")
    public Long getDbapplicationfk() {
        return dbapplicationfk;
    }
    public void setDbapplicationfk(final Long dbapplicationfk) {
        this.dbapplicationfk = dbapplicationfk;
    }

    @Column(name="REQUESTOR")
    public String getUserDetail() {
        return userDetail;
    }
    public void setUserDetail(final String userDetail) {
        this.userDetail = userDetail;
    }
    @Column(name="DMLASTUPDATE")
    public Date getDmlastupdate() {
        return dmlastupdate;
    }
    public void setDmlastupdate(final Date dmlastupdate) {
        this.dmlastupdate = dmlastupdate;
    }

    private String dmlScriptName;
    @Column(name="DML_SCRIPTNAME")
    public String getDmlScriptName() {
        return dmlScriptName;
    }
    public void setDmlScriptName(final String dmlScriptName) {
        this.dmlScriptName = dmlScriptName;
    }
    private Blob dmlScript;
    @Column(name="DML_SCRIPT")
    @Lob
    public Blob getDmlScript() {
        return dmlScript;
    }
    public void setDmlScript(final Blob dmlScript) {
        this.dmlScript = dmlScript;
    }

    @Column(name="STATUS")
    public String getStatus() {
        return status;
    }
    public void setStatus(final String status) {
        this.status = status;
    }
    @Column(name="DATEEXECUTED")
    public Date getDateExecuted() {
        return dateExecuted;
    }
    public void setDateExecuted(final Date dateExecuted) {
        this.dateExecuted = dateExecuted;
    }
    @Column(name="PATCHVERSION")
    public Long getPatchVersion() {
        return patchVersion;
    }
    public void setPatchVersion(final Long patchVersion) {
        this.patchVersion = patchVersion;
    }
    @Column(name="MINORVERSION")
    public Long getMinorVersion() {
        return minorVersion;
    }
    public void setMinorVersion(final Long minorVersion) {
        this.minorVersion = minorVersion;
    }

    @Column(name="MAJORVERSION")
    public Long getMajorVersion() {
        return majorVersion;
    }
    public void setMajorVersion(final Long majorVersion) {
        this.majorVersion = majorVersion;
    }
}

Please note dml_script is of type Blob, but hibernate 3 is firing following query.

Caused by: java.sql.BatchUpdateException: Batch entry 0 insert into PMD14_DB_VERSION (DATEEXECUTED, DB_APPLICATION_FK, DML_SCRIPT, DML_SCRIPTNAME, DMLASTUPDATE, MAJORVERSION, MINORVERSION, PATCHVERSION, STATUS, REQUESTOR, ID) values ('2012-02-08 14:27:25.383000 +05:30:00', '1', '31129', 'test.sql', '2012-02-08 14:27:25.243000 +05:30:00', '1', '1', '1', 'A', 'user', '1') was aborted.  Call getNextException to see the cause.

What should be the type of dml_script in java?

Rajesh
  • 2,934
  • 8
  • 42
  • 71
  • Maybe look at that http://stackoverflow.com/a/3739047/320180 – ndeverge Feb 08 '12 at 09:44
  • @nide_ekito I have read this post ..but didint got any solution out of that..I have changed bytea type to OID ,so now not getting exception..Is it correct to change bytea type to oid? – Rajesh Feb 08 '12 at 10:36
  • @Rajesh: you should use `bytea` for a BLOB column. –  Feb 08 '12 at 10:41
  • @ a_horse_with_no_name The data type in java should be Blob or byte[] because with Blob I am getting the error posted in the question – Rajesh Feb 08 '12 at 10:56
  • ya with byeta datatype in PostGreSQL and byte[] data type in mapping ,things are working,but my doubt was with this setting if I switch database to Oracle XE will it work properly..note in oracle I wil create Bolb type and mapping will remain same – Rajesh Feb 08 '12 at 11:23
  • should work. AFAIK bytea is blob type in oracle – Firo Feb 08 '12 at 16:24
  • @Rajesh: Could you post the answer in the answers section? I would be happy to upvote it to close this question out. – Chris Travers Mar 14 '13 at 11:46

0 Answers0