1

hibernate.hbm2ddl.auto="update" works strange. Any database entity.. if not there in database (table in database and column in table) will be created by keeping UPDATE. But if I want to change any existing datatype OR size of any column then it doesn't work. In this way I make a mind set that UPDATE creates thing but does not update. But when I tried to add a constraint (which was not-null) then again it did nothing. No constraint been added.

Please suggest How can I proceed in situation where I can not use CREATE but still I want to change things like datatype of any column OR size of any column. I have gone through many documentation and answers but none of them gave reason.

I am using hibernate 4.0.0 with MySQL-5.6.12..

Thanks in advance.....

2 Answers 2

2

Using hibernate.hbm2ddl.auto="update"

You can't add a new not null constraint when there are already existing data in the table.

May be check what happens if you try with nullable constraint.

1
  • @Jay... I've tried on a empty table so there is no question of older existing data. not-null constraint was just an example to denote that UPDATE is not adding addition constraint. I want to change datatype OR size given to a particular column then what can be the solution ? And obviously I can't use CREATE...
    – Jain
    Commented May 6, 2014 at 13:38
2
hibernate.hbm2ddl.auto="update"

Will definitely update changes made in Entity if its valid, only while creating SessionFactory object. "create" will create fresh data base tables while creating SessionFactory object.

create - doing creating schema
update - updating existing schema
validate - validate existing schema
create-drop - create and drop the schema automatically when session is starts and ends.

update will not behave properly for existing data, So don't use update in production.Because some times say changing data type may not be valid. You can refer this question.

My suggestion : Just take a backup of your data from your data base.Then make changes what ever you need like increase size,change data type(it should be compatible with old one). Then at last import data into your newly generated data base structure.

1
  • @mahesh... My problem is If I want to change datatype OR size given to a particular then what can be the solution ? In my case I have try to do same operations via UPDATE. But they are not getting updated. CREATE is alright but it will delete older data and obviously this is not acceptable.
    – Jain
    Commented May 6, 2014 at 13:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.