Sumeet Sumeet - 1 year ago 95
Java Question

Changing Data type of model object in hibernate after creation

I am learning hibernate . I am bit confused with update property . Change in model object data type is not changing data type of table in mysql.

Firstly I have created User Pojo with userId as data type int . Initially I have made hbm2dll property as CREATE .

public class User {
private int userid;
private String username;


For persisting data firstly I have created user object like below and saved using sessionFactory .

User user = new user();
user.setUsername("First User");

Because of above effort User table got created where userid data is int.

But later I changed the pojo’s userid data type to string .

Also I changed hbm2ddl property to update .

So after this change even user object is having string as userid , table userid data type is not changing to varchar . How to change the data type of table using hibernate .

dit dit
Answer Source

I believe update can not change the data type.

Imagine the field of type string will be change to Integer. What will happen to existing data?

So update (data type update) can not be guaranteed if the table is not empty.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download