#how to trigger defaults on a DB column

1 messages · Page 1 of 1 (latest)

wooden wing
#

how to trigger defaults on a DB column,
ive tryed not adding anything, ive tryed adding null, but in the database the value is always empty, the default never triggers.

heady wigeonBOT
#

<@&987246584574140416> please have a look, thanks.

#
TJ-Bot
How to trigger defaults on a DB column, ive tryed not adding anything, ive tryed adding null, but in the database the value is always empty, the default never triggers. in spring java using jpa repo

To trigger defaults on a DB column in a Spring Java application using JPA, you can follow these steps:

  1. Make sure the default value is set in the database schema for the column in question.
  2. In your entity class, do not set a value for the column that has a default value in the database.
  3. When saving an entity with this column using JpaRepository's save() method, ensure that the column is not explicitly set to null or any other value.

If you have tried not adding anything or adding null when saving an entity and the default value is still not triggered, there might be something else overriding the default value. Check if there are any triggers or constraints in place that could be affecting the default value setting.

Additionally, you can try setting the insertable attribute to false in your @Column annotation for this column in your entity class. This will prevent any values from being inserted into this column during database operations, allowing the default value to be used instead.

By following these steps and ensuring that no conflicting settings are overriding the default value, you should be able to successfully trigger defaults on a DB column in your Spring Java application using JPA.