i have some questions, below is my implementation :
the DB table result will show below :
my question here :
1)if i would like to have country_id to be string , for example country_id like "JP" , and i have modify the coutry.hbm.xml as above, it prompt me error like Table server.country' doesn't exist , is it the right way to do it ?
I think there is a little bit of a disconnect on how/why to use Hibernate.
Hibernate is used to do Object-Relational Mapping. Meaning that Hibernate will take your object model and then persist that object model to your relational database.
So take the following example:
When we're setting a Country on a User we're actually setting the entire object that we are using to represent a Country on our User.
We are not setting a specific value of that Country's value on the User.
So the database tables would like the following for storing the above classes:
The above are tables that are in a specific normal form. One of the reasons for using relational databases, to reduce the amount of duplicated data.
With what you're doing by placing the name of the country in the User table, is you're lowering your normal form of your database. Which is fine, but what is the purpose of the country table? Its not even being referenced and therefore there isn't any referential integrity.
My guess is you're trying to build something called a FACT table that is easy to query. If that is your case then you will need to rethink how you're using hibernate.