Hibernate MySQL View operation

Source: Internet
Author: User
Tags mysql view

Hibernate view operations, first establish database views

View V_invite:

Create
View Pintu.v_invite as
Select
cp.user_id as be_user_id,
CAI.ACTIVITY_INVITE_ID,
CAI.PERSON_ID,
Cai.person_name,
CAI.BE_PERSON_ID,
CAI.ACTIVITY_ID,
Cai.invite_time
From
Ptcom.com_person CP,
Ptcom.com_activity_invite Cai
where
cp.person_id = cai.be_person_id

Generating Hibernate view mapping mappings

<class name= "Com.test.pojo.entity.VComActivityInvite" table= "V_com_activity_invite" catalog= "Pintu" >
<composite-id name= "id" class= "com.test.pojo.entity.VComActivityInviteId" >
<key-property name= "Beuserid" type= "java.lang.String" >
<column name= "be_user_id" length= "/>"
</key-property>
<key-property name= "Activityinviteid" type= "Java.lang.Long" >
<column name= "activity_invite_id"/>
</key-property>
<key-property name= "PersonId" type= "Java.lang.Long" >
<column name= "person_id"/>
</key-property>
<key-property name= "PersonName" type= "java.lang.String" >
<column name= "person_name" length= "/>"
</key-property>
<key-property name= "Bepersonid" type= "Java.lang.Long" >
<column name= "be_person_id"/>
</key-property>
<key-property name= "ActivityID" type= "Java.lang.Long" >
<column name= "activity_id"/>
</key-property>
<key-property name= "Invitetime" type= "Java.util.Date" >
<column name= "invite_time" length= "/>"
</key-property>
</composite-id>
</class>

Pojo:vcomactivityinvite for sexual entities

public class Vcomactivityinvite implements Java.io.Serializable {

Fields

Private Vcomactivityinviteid ID;

Constructors


Public Vcomactivityinvite () {
}


Public vcomactivityinvite (Vcomactivityinviteid ID) {
This.id = ID;
}

Property accessors

Public Vcomactivityinviteid getId () {
return this.id;
}

public void SetId (Vcomactivityinviteid id) {
This.id = ID;
}

}

Corresponding View data body: Vcomactivityinviteid

public class Vcomactivityinviteid implements Java.io.Serializable {

Fields

Private String Beuserid;
Private Long Activityinviteid;
Private Long personId;
Private String personname;
Private Long Bepersonid;
Private Long ActivityID;
Private Date Invitetime;

Constructors


Public Vcomactivityinviteid () {
}


Public Vcomactivityinviteid (Long Activityinviteid) {
This.activityinviteid = Activityinviteid;
}


Public Vcomactivityinviteid (String Beuserid, Long Activityinviteid,
Long personId, String personname, Long Bepersonid, long ActivityID,
Date invitetime) {
This.beuserid = Beuserid;
This.activityinviteid = Activityinviteid;
This.personid = personId;
This.personname = PersonName;
This.bepersonid = Bepersonid;
This.activityid = ActivityID;
This.invitetime = Invitetime;
}

Property accessors

Public String Getbeuserid () {
return This.beuserid;
}

public void Setbeuserid (String beuserid) {
This.beuserid = Beuserid;
}

Public Long Getactivityinviteid () {
return This.activityinviteid;
}

public void Setactivityinviteid (Long activityinviteid) {
This.activityinviteid = Activityinviteid;
}

Public Long Getpersonid () {
return This.personid;
}

public void Setpersonid (Long personId) {
This.personid = personId;
}

Public String Getpersonname () {
return this.personname;
}

public void Setpersonname (String personname) {
This.personname = PersonName;
}

Public Long Getbepersonid () {
return This.bepersonid;
}

public void Setbepersonid (Long bepersonid) {
This.bepersonid = Bepersonid;
}

Public Long Getactivityid () {
return This.activityid;
}

public void Setactivityid (Long ActivityID) {
This.activityid = ActivityID;
}

Public Date Getinvitetime () {
return this.invitetime;
}

public void Setinvitetime (Date invitetime) {
This.invitetime = Invitetime;
}

public boolean equals (Object other) {
if ((this = other))
return true;
if ((other = = null))
return false;
if (! ( Other instanceof Vcomactivityinviteid))
return false;
Vcomactivityinviteid Castother = (Vcomactivityinviteid) Other;

Return ((This.getbeuserid () = = Castother.getbeuserid ()) | | (This
. Getbeuserid ()! = NULL
&& Castother.getbeuserid ()! = null && This.getbeuserid ()
. Equals (Castother.getbeuserid ())))
&& (This.getactivityinviteid () = = Castother
. Getactivityinviteid ()) | | (This.getactivityinviteid ()! = NULL
&& Castother.getactivityinviteid ()! = NULL && this
. Getactivityinviteid (). Equals (
Castother.getactivityinviteid ())))
&& ((this.getpersonid () = = Castother.getpersonid ()) | | (This
. Getpersonid ()! = NULL
&& Castother.getpersonid ()! = NULL && this
. Getpersonid (). Equals (Castother.getpersonid ())))
&& ((this.getpersonname () = = Castother.getpersonname ()) | | (This
. getpersonname ()! = NULL
&& castother.getpersonname ()! = NULL && this
. Getpersonname (). Equals (Castother.getpersonname ())))
&& ((this.getbepersonid () = = Castother.getbepersonid ()) | | (This
. Getbepersonid ()! = NULL
&& Castother.getbepersonid ()! = NULL && this
. Getbepersonid (). Equals (Castother.getbepersonid ())))
&& ((This.getactivityid () = = Castother.getactivityid ()) | | (This
. Getactivityid ()! = NULL
&& Castother.getactivityid ()! = NULL && this
. Getactivityid (). Equals (Castother.getactivityid ())))
&& ((this.getinvitetime () = = Castother.getinvitetime ()) | | (This
. getinvitetime ()! = NULL
&& castother.getinvitetime ()! = NULL && this
. Getinvitetime (). Equals (Castother.getinvitetime ()));
}

public int hashcode () {
int result = 17;

result = PNS * result
+ (Getbeuserid () = = null? 0:this.getbeuserid (). Hashcode ());
result = 37
* Result
+ (Getactivityinviteid () = = null? 0:this
. Getactivityinviteid (). Hashcode ());
result = PNS * result
+ (Getpersonid () = = null? 0:this.getpersonid (). Hashcode ());
result = 37
* Result
+ (getpersonname () = = null? 0:this.getpersonname ()
. Hashcode ());
result = 37
* Result
+ (Getbepersonid () = = null? 0:this.getbepersonid ()
. Hashcode ());
result = 37
* Result
+ (Getactivityid () = = null? 0:this.getactivityid ()
. Hashcode ());
result = 37
* Result
+ (getinvitetime () = = null? 0:this.getinvitetime ()
. Hashcode ());
return result;
}

}

In the operation, the view is queried to introduce the query criteria:

String hql = "SELECT count (*) from Vcomactivityinvite VCA where VCA. ID. Beuserid = ' "+ userid+" ' ";
return (number) Vcomactivityinvitedao.createquery (HQL). Uniqueresult ()). Intvalue ();

Parent class ID corresponds to <composite-id name= "id" class= "com.test.pojo.entity.VComActivityInviteId" >

hibernate3.2 the corresponding statistic number returns a long type, which needs to be converted as follows

(number) Vcomactivityinvitedao.createquery (HQL). Uniqueresult ()). Intvalue

Hibernate MySQL View operation

Related Article

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.