Hibernate: Automatic Versioning Nullable Column
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 manage开发者_如何学Pythons 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.
精彩评论