Tuesday, March 11, 2014

Resolved : Set the Database Default Value in a Hibernate/JPA Save Persist

Removed
Using JPA (with Hibernate), I was inserting a record in my database. In my table, one column is defined with a DEFAULT Value.
But when I insert a save, persist my record, JPA put it as NULL.
So using JPA, the solution was to use insertable = false in the column definition. JPA will ignore then that column while inserting in the Database and the default value will be used.

@Column(name = "myColumn", length = 35, insertable = false)

5 comments :

  1. Hello Mariem, content de voir que tu refais du JAVA ;)

    ReplyDelete
    Replies
    1. Salut Sothea, Eh bah oui je suis toujours fidele au Java ;0 Bon la c'est du JPA aussi

      Delete
    2. Is there Anyway to allow user to set the value when inserting and, if user haven't set the value apply the default value?

      Delete
  2. This comment has been removed by a blog administrator.

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete

Articles les plus consultés