1. Beans
A. Version Bean
Package Locationservice.beans;import Java.sql.timestamp;import Java.util.arraylist;import java.util.List;import Javax.persistence.*;import Org.hibernate.annotations.genericgenerator;import locationService.beans.Entities; Import Locationservice.beans.attribute;import Locationservice.beans.attributetag;import Locationservice.beans.entitytoentity;import LocationService.beans.Tag; @Entity @table (name = "Version") public class Version {private int versionId; Private Boolean complete; Private Timestamp editdate; Private String author; Private String description; private int Preversionid; Private list<entities> entities = new arraylist<entities> (); Private list<attribute> Attribute = new arraylist<attribute> (); Private list<attributetag> Attributetag = new arraylist<attributetag> (); Private list<entitytoentity> entitytoentity = new arraylist<entitytoentity> (); Private list<tag> Tag = new arraylist<tag> (); @Id @GeneratedVaLue (generator = "increment") @GenericGenerator (name = "Increment", strategy = "increment") @Column (name= "version_id") p ublic int Getversionid () {return versionId; } public void Setversionid (int versionId) {This.versionid = VersionId; } @Column (name= "complete") public boolean Getcomplete () {return complete; } public void SetComplete (Boolean complete) {this.complete = complete; } @Column (name= "edit_date") public Timestamp geteditdate () {return editdate; } public void Seteditdate (Timestamp editdate) {this.editdate = editdate; } @Column (name= "author") Public String Getauthor () {return author; } public void Setauthor (String author) {this.author = author; } @Column (name= "description") public String getdescription () {return description; } public void SetDescription (String description) {this.description = description; } @Column (name= "pre_version_id") public int Getpreversionid () {return preversionid; } public void Setpreversionid (int preversionid) {This.preversiOnid = Preversionid; } @OneToMany (cascade = cascadetype.all) @JoinColumn (name = "version_id", Nullable = false) public List<entities> ; Getentities () {return entities; } public void Setentities (list<entities> entities) {this.entities = entities; } @Override Public String toString () {return ' versionId is ' + versionId + ', Preversionid is ' + Preversionid + ' , author is "+ author; } }
B. Entities Bean
package Locationservice.beans;import Javax.persistence.*;import Org.hibernate.annotations.GenericGenerator; @Entity @table (name = "Entities") public class entities {private int EntityId; Private String label; Public enum EntityType {location, group; } private EntityType Locationorgroup; @Id @Column (name= "entity_id") public int Getentityid () {return entityid; } public void Setentityid (int entityid) {This.entityid = EntityId; } @Column (name= "label") public String Getlabel () {return label; public void SetLabel (String label) {this.label = label; } @Column (name= "Location_or_group") @Enumerated (enumtype.string) public EntityType Getlocationorgroup () {return locat Ionorgroup; } public void Setlocationorgroup (EntityType locationorgroup) {this.locationorgroup = Locationorgroup; } @Override Public String toString () {return ' EntityId is ' + EntityId + ', label is ' + Label + ', Locationorgroup is "+ locationorgroup; }}
2. Call Method
/** * Check Whether this entities ID have been in the version * /public boolean CHECKENTITIESPK (version Versio n, int EntityId) { Session session = Config.getsessionfactory (). Opensession (); Session.begintransaction (); int versionId = Version.getversionid (); Query query = Session.createquery ("from entities where EntityId =: EntityId and version_id =: VersionId"); Query.setparameter ("EntityId", EntityId); Query.setparameter ("VersionId", versionId); @SuppressWarnings ("unchecked") list<entities> o = query.list (); if (o = = NULL | | o.size () = = 0) { return false; } return true; }
Hibernate CreateQuery Call Joincolumn