ASP.NET&Spring.NET&NHibernate最佳实践(十)——第4章权限子系统(3)

4.2. 权限子系统映射文件(HBM)
Application.hbm.xml
<? xml version="1.0" encoding="utf-8"  ?>
< hibernate-mapping  xmlns ="urn:nhibernate-mapping-2.2" >
  
< class  name ="Guushuuse.SalaryPrj.Security.DomainModel.Application, Guushuuse.SalaryPrj.Security"  table ="t_applications" >
    
< id  name ="ID"  column ="application_id"  type ="Int32"   unsaved-value ="-1" >
      
< generator  class ="identity"   />
    
</ id >

    
< property  name ="Name"  column ="application_name"  type ="String"  length ="255"  not-null ="true"   />
    
< property  name ="Description"  column ="description"  type ="String"  length ="255"  not-null ="false"   />

  
</ class >
</ hibernate-mapping >

Role.hbm.xml
<? xml version="1.0" encoding="utf-8"  ?>
< hibernate-mapping  xmlns ="urn:nhibernate-mapping-2.2" >
  
< class  name ="Guushuuse.SalaryPrj.Security.DomainModel.Role, Guushuuse.SalaryPrj.Security"  table ="t_roles" >
    
< id  name ="ID"  column ="role_id"  type ="Int32"   unsaved-value ="-1" >
      
< generator  class ="identity"   />
    
</ id >

    
< property  name ="Name"  column ="role_name"  type ="String"  length ="255"  not-null ="true"   />
    
< property  name ="Description"  column ="description"  type ="String"  length ="255"  not-null ="false"   />

    
< many-to-one  name ="Application"  column ="application_id"  class ="Guushuuse.SalaryPrj.Security.DomainModel.Application, Guushuuse.SalaryPrj.Security"  not-null ="true"   />

  
</ class >
</ hibernate-mapping >

User.hbm.xml
<? xml version="1.0" encoding="utf-8"  ?>
< hibernate-mapping  xmlns ="urn:nhibernate-mapping-2.2" >
  
< class  name ="Guushuuse.SalaryPrj.Security.DomainModel.User, Guushuuse.SalaryPrj.Security"  table ="t_users" >
    
< id  name ="ID"  column ="user_id"  type ="Int32"   unsaved-value ="-1" >
      
< generator  class ="identity"   />
    
</ id >

    
< property  name ="Username"  column ="user_username"  type ="String"  length ="255"  not-null ="true"   />
    
< property  name ="Email"  column ="user_email"  type ="String"  length ="255"  not-null ="false"   />
    
< property  name ="Password"  column ="user_password"  type ="String"  length ="128"  not-null ="true"   />
    
< property  name ="PasswordFormat"  column ="password_format"  not-null ="true"   />
    
< property  name ="PasswordSalt"  column ="password_salt"  type ="String"  length ="128"  not-null ="true"   />
    
< property  name ="PasswordQuestion"  column ="password_question"  type ="String"  length ="255"  not-null ="false"   />
    
< property  name ="PasswordAnswer"  column ="password_answer"  type ="String"  length ="128"  not-null ="false"   />
    
< property  name ="IsAnonymous"  column ="is_anonymous"  type ="TrueFalse"  not-null ="true"   />
    
< property  name ="IsApproved"  column ="is_approved"  type ="TrueFalse"  not-null ="true"   />
    
< property  name ="IsLockedOut"  column ="is_locked_out"  type ="TrueFalse"  not-null ="true"   />
    
< property  name ="CreateDate"  column ="create_date"  type ="DateTime"  not-null ="true"   />
    
< property  name ="LastActivityDate"  column ="last_activity_date"  type ="DateTime"  not-null ="true"   />
    
< property  name ="LastLoginDate"  column ="last_login_date"  type ="DateTime"  not-null ="true"   />
    
< property  name ="LastPasswordChangedDate"  column ="last_password_changed_date"  type ="DateTime"  not-null ="true"   />
    
< property  name ="LastLockoutDate"  column ="last_lockout_date"  type ="DateTime"  not-null ="true"   />
    
< property  name ="FailedPasswordAttemptCount"  column ="f_pwd_attempt_count"  type ="Int32"  not-null ="true"   />
    
< property  name ="FailedPasswordAttemptWindowStart"  column ="f_pwd_attempt_win_start"  type ="DateTime"  not-null ="true"   />
    
< property  name ="FailedPasswordAnswerAttemptCount"  column ="f_pwd_answer_attempt_count"  type ="Int32"  not-null ="true"   />
    
< property  name ="FailedPasswordAnswerAttemptWindowStart"  column ="f_pwd_answer_attempt_win_start"  type ="DateTime"  not-null ="true"   />
    
< property  name ="Comment"  column ="user_comment"  type ="String"  length ="255"  not-null ="false"   />

    
< many-to-one  name ="Application"  column ="application_id"  class ="Guushuuse.SalaryPrj.Security.DomainModel.Application, Guushuuse.SalaryPrj.Security"  not-null ="true"   />

    
< bag  name ="Roles"  table ="t_users_roles"  lazy ="false" >
      
< key  column ="user_id"   />
      
< many-to-many  class ="Guushuuse.SalaryPrj.Security.DomainModel.Role, Guushuuse.SalaryPrj.Security"  column ="role_id"  outer-join ="true"   />
    
</ bag >

  
</ class >
</ hibernate-mapping >

你可能感兴趣的:(Hibernate)