Nik Kashi
Nik Kashi

Reputation: 4606

Set fixed value for Hibernate insert in Oracle view

I am create a view in oracle 10g like this:

    CREATE OR REPLACE FORCE VIEW vw_pikap_approle
AS
   SELECT approle_id, approle_name, creation_timestamp,1 is_pikap
     FROM approle
    WHERE is_pikap = 1
/

but after inserting

INSERT INTO vw_pikap_approle (approle_id, approle_name, creation_timestamp)
     VALUES (hibernate_sequence.NEXTVAL, 'dddd', SYSDATE)

is_pikap is 0 ( as default in DB) , so is_pikap is fixed in view as 1.

Is there any solution for setting fixed value while inserting in Oracle view

This need is because of reducing Hibernate mapping in java application.

I need a hibernate or view solution for this problem.

I am using this mapping for may .hbm.xml:

<property
        name="isPikap"
        type="int"
        column="IS_PIKAP"
        not-null="true"
        length="1"
        formula="1"
        />

and in my java entity:

private int isPikap = 1;
public int getIsPikap() {
    return isPikap;
}
public void setIsPikap(int i) {
    isPikap=1;
}

but generated query with hibernate insert is:

Hibernate: insert into VW_PIKAP_APPROLE (APPROLE_NAME, APPROLE_ID) values (?, ?)

so when i using debugger the isPikap value of java entity is 1!

Upvotes: 0

Views: 784

Answers (1)

Luca Basso Ricci
Luca Basso Ricci

Reputation: 18413

I think you can't insert data into this view because is_pikap is derived from an expression.
With Hibernate I suppose you can create your view mapping making is_pikap final and initialized to 1

@Entity
@Table("vw_pikap_approle")
class vw_pikap_approle {
  @Column(name="is_pikap")
  private final int is_pikap = 1;

  /* Other properties with accessors  */
}

Upvotes: 1

Related Questions