Hibernate annotation Configuration 1n,n1 Example
Last Update:2016-07-19
Source: Internet
Author: User
<span id="Label3"></p><p><p>Package com.entity;</p></p><p><p>Import java.util.HashSet;<br>Import java.util.Set;</p></p><p><p>Import javax.persistence.Entity;<br>Import javax.persistence.GeneratedValue;<br>Import javax.persistence.GenerationType;<br>Import javax.persistence.Id;<br>Import javax.persistence.OneToMany;<br>Import javax.persistence.Table;</p></p><p><p>Import org.hibernate.annotations.Cache;<br>Import org.hibernate.annotations.CacheConcurrencyStrategy;</p></p><p><p>@Entity<br>@Table (name= "role")<br><br>public class Roleinfo {</p></p><p><p>Private Integer roleid;<br>Private String roleName;<br>Private set<userinfo> users=new hashset<userinfo> ();<br><br>@Id<br>@GeneratedValue (strategy=generationtype.identity)<br>Public Integer Getroleid () {<br>Return roleid;<br>}<br>public void Setroleid (Integer Roleid) {<br>This.roleid = roleid;<br>}<br>Public String getrolename () {<br>Return roleName;<br>}<br>public void Setrolename (String RoleName) {<br>This.rolename = roleName;<br>}<br><br><br>@OneToMany (mappedby= "role")<br>Public set<userinfo> getusers () {<br>Return users;<br>}<br>public void Setusers (set<userinfo> Users) {<br>This.users = users;<br>}<br><br>}</p></p><p><p></p></p><p><p></p></p><p><p>Package com.entity;</p></p><p><p>Import java.util.Date;</p></p><p><p>Import javax.persistence.Entity;<br>Import javax.persistence.GeneratedValue;<br>Import javax.persistence.GenerationType;<br>Import javax.persistence.Id;<br>Import javax.persistence.JoinColumn;<br>Import javax.persistence.ManyToOne;<br>Import javax.persistence.NamedNativeQuery;<br>Import javax.persistence.NamedQuery;<br>Import javax.persistence.Table;</p></p><p><p>@Entity<br>@Table (name= "user")<br>public class UserInfo {</p></p><p>Private Integer userId;<br>Private String username;<br>Private String password;<br>Private String realname;<br>Private Date birthday;<br>Private Roleinfo role;<br><br>@Id<br>@GeneratedValue (strategy=generationtype.identity)<br>Public Integer getUserId () {<br>Return userId;<br>}<br>public void Setuserid (Integer UserId) {<br>This.userid = userId;<br>}<br>Public String GetUserName () {<br>Return username;<br>}<br>public void Setusername (String Username) {<br>This.username = username;<br>}<br>Public String GetPassword () {<br>Return password;<br>}<br>public void SetPassword (String Password) {<br>This.password = password;<br>}<br>Public String getrealname () {<br>Return realname;<br>}<br>public void Setrealname (String Realname) {<br>This.realname = realname;<br>}<br>Public Date Getbirthday () {<br>Return birthday;<br>}<br>public void Setbirthday (Date Birthday) {<br>This.birthday = birthday;<br>}<br><br>@ManyToOne<br>@JoinColumn (name= "roleid")<br>Public Roleinfo getrole () {<br>Return role;<br>}<br>public void Setrole (roleinfo Role) {<br>This.role = role;<br>}<br>@Override<br>Public String toString () {<br>return "UserInfo [userid=" + userId + ", username=" + username<br>+ ", password=" + password + ", realname=" + realname<br>+ ", birthday=" + birthday + ", role=" + role + "]";<br>}<br>Public UserInfo () {<br><br>}<br>Public UserInfo (string username, string Password) {<br>Super ();<br>This.username = username;<br>This.password = password;<br>}<br><br>}</p><p><p>Hibernate annotation Configuration 1n,n1 Example</p></p></span>