Hibernate annotation Configuration 1n,n1 Example

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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.