문제

I have a table which contains huge data. I want to add hibernate automatic versioning to this table. But adding a not-null column to this table for versioning is very expensive due to huge data. Is there a workaround so hibernate can work with nullable column? Currently hibernate gives NPE because it tries to increment a null value. ( As hibernate manages this internally, changing the version value on client side is out of question ) Any other versioning startegy is welcome too. Thanks in advance

도움이 되었습니까?

해결책

If your flavour of database permits it you could 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 may still want to benchmark its performance against a realistic volume of data. It may not solve your problem.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top