Reputation: 119
I have a job that runs every midnight and I am using JPA to create tables. I want to assign a default value to a column (for all the rows existing in the current db) every time I start the job and then during the job I will assign that column a different value depending on some logic.
For example:
@Column(name = "delete_YN?")
private String deleteYN = "Y";
//getters setters here
I want this column to have a default value "Y" every time my job starts (each row inserted in the previous run should have the column value as "Y" at the start of the job) and the job assigns the value "N" to the column by some logic. In the end, I would be able to see which rows have the Y value and which ones have the N value to this column. Am I doing this correctly? Is this okay or should use the columnDefinition annotation? What exactly is the difference between this and the columnDefinition annotation?
Upvotes: 5
Views: 14189
Reputation: 8272
@Column
JavaDoc of columnDefinition
/**
* (Optional) The SQL fragment that is used when
* generating the DDL for the column.
* <p> Defaults to the generated SQL to create a
* column of the inferred type.
*/
columnDefinition that you should use is (for Oracle)
@Column(name="delete_YN", columnDefinition="varchar2(1) DEFAULT 'Y'`")
But i think that your way is better because for the columnDefinition you're tying to db.
I suggest you also these links.... link1 and link2
I hope I've given you all the answers about your question.
Upvotes: 3