java - How to represent a legacy database using Hibernate? -
i have follow legacy database structure , content:
order parameter value -------------------------------- 1 user_login user 1 user_password 123456 1 user_level basic 2 user_login admin 2 user_password s3k42k 2 user_level advanced
i represent below , utilize entity called 'user' can abstract complexity of legacy structure:
id user password level ------------------------------- 1 user 123456 basic 2 admin s3k42k advanced
i got using view in database, couldnt update using view. there way represent legacy structure using hibernate can update too?
your best approach normalize table. make things easier in long run. 1 thing try not option, create table called user holds @ least primary key , id of users information in parameter table. allow treat relationship one-to-many , map hibernate. example following:
note might have mapping wrong did off of top of head illustrate point.
@entity class parameter{ @column(name="order") private int order; @column(name="parameter") private string parameter; @column(name="value") private string value; } @entity class user{ @column(name="id") private int id; @onetomany(cascade=all) @jointable(name="secondary", joincolumns={@joincolumn(name="id")}, inversejoincolumns=@joincolumn(name="order")) @mapkeyjoincolumn(name="parameter") private map<string,parameter> userdata; public string getusername(){ return userdata.get("user_login") } etc. }
Comments
Post a Comment