开发者

Hibernate Error - while inserting from select

开发者 https://www.devze.com 2022-12-07 18:33 出处:网络
Basically, for some reason, I need to conditionally insert data from one table to another, for later use in postgres.

Basically, for some reason, I need to conditionally insert data from one table to another, for later use in postgres.

I am doing this within a spring boot app, with legacy hibernate SQLQuery implementation.

For purpose, created a destination table below with exact column type in source table

CREATE TABLE billing_query (
    id float8 NOT NULL,
    created_ts timestamp(6) NOT NULL,
    trip_date timestamp(0) NULL,
    CONSTRAINT billing_query_pk PRIMARY KEY (id, created_ts)
   );

Below is hbm mapping:

<hibernate-mapping package="xyz.model">

    <class name="BillingQuery" table="BILLING_QUERY">
        <id column="ID" name="id"/>
        <property name="createdTs" column="CREATED_TS" type="java.util.Date" />
        <property name="tripDate" column="TRIP_DATE" type="timestamp" />
    </class>

</hibernate-mapping>

And Model开发者_JAVA百科:

public class BillingQuery implements Serializable {

    private Long id;

    private Date createdTs;
   
    private Date startOfTripDate;
}

But whenever I am trying to execute query (insert from select), the app is throwing below error

Error: column "created_ts" is of type timestamp without time zone but expression is of type character varying

Below is the printed sql query (with java.util.date being passed as paramter)

insert into billing_query 
select t.ID as ID, t.CREATED_TS as CREATED_TS, t.TRIP_DATE as TRIP_DATE 
from trip t 
where t.TRIP_DATE = ? 
  and t.FLAG='Y' 

Mapping in java:

query.setTimestamp(i++, eq.getSot());

Appreciate any assistance in same regards. Tried casting using ::timestamp and to_timestamp in select but still same error.

0

精彩评论

暂无评论...
验证码 换一张
取 消