Hibernate: Automatically maintain Nullable Column versions

I have a table containing huge data. I want to add hibernate automatic version control to this table. But adding a not-null column to this table for version control is very expensive due to the huge data. Is there a workaround so sleep mode can work with a null column? Hibernate is currently giving NPE because it is trying to increase the null value. (Since hibernate manages this internally, changing the version value on the client side is out of the question) Any other starting version is also welcome. thanks in advance

+3
source share
1 answer

If your flavor of the database allows this, you can use the DEFAULT option. This is against Oracle ...

SQL> create table t23 as select object_id as id from user_objects;

Table created.

SQL> desc t23
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 ID                                                 NUMBER

SQL> alter table t23 add hibernate_version_number number default 0 not null;

Table altered.

SQL> desc t23
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 ID                                                 NUMBER
 HIBERNATE_VERSION_NUMBER                  NOT NULL NUMBER

SQL> select count(*) from t23 where hibernate_version_number = 0;

  COUNT(*)
----------
       504

SQL>

However, you can still compare performance with a realistic amount of data. This may not solve your problem.

+2
source

Source: https://habr.com/ru/post/1730194/


All Articles