I have two table
1. speeddemaill
2. highspeedd
speeddemail.java
Code:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package pip;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
/**
*
* @author baktha
*/
@Entity
@Table(name = "speedemaill")
//@NamedQueries({@NamedQuery(name = "Speedemaill.findAll", query = "SELECT s FROM Speedemaill s"), @NamedQuery(name = "Speedemaill.findById", query = "SELECT s FROM Speedemaill s WHERE s.id = :id"), @NamedQuery(name = "Speedemaill.findByHeader", query = "SELECT s FROM Speedemaill s WHERE s.header = :header"), @NamedQuery(name = "Speedemaill.findByClientId", query = "SELECT s FROM Speedemaill s WHERE s.clientId = :clientId"), @NamedQuery(name = "Speedemaill.findByObjectId", query = "SELECT s FROM Speedemaill s WHERE s.objectId = :objectId"), @NamedQuery(name = "Speedemaill.findByDisplay", query = "SELECT s FROM Speedemaill s WHERE s.display = :display"), @NamedQuery(name = "Speedemaill.findByValue", query = "SELECT s FROM Speedemaill s WHERE s.value = :value"), @NamedQuery(name = "Speedemaill.findByLongi", query = "SELECT s FROM Speedemaill s WHERE s.longi = :longi"), @NamedQuery(name = "Speedemaill.findByLat", query = "SELECT s FROM Speedemaill s WHERE s.lat = :lat"), @NamedQuery(name = "Speedemaill.findByComments", query = "SELECT s FROM Speedemaill s WHERE s.comments = :comments"), @NamedQuery(name = "Speedemaill.findByGpsTime", query = "SELECT s FROM Speedemaill s WHERE s.gpsTime = :gpsTime"), @NamedQuery(name = "Speedemaill.findByTimestamp", query = "SELECT s FROM Speedemaill s WHERE s.timestamp = :timestamp")})
public class Speedemaill implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "ID")
private Integer id;
@Column(name = "Header")
private String header;
@Column(name = "ClientId")
private Integer clientId;
@Column(name = "ObjectId")
private Integer objectId;
@Column(name = "Display")
private String display;
@Column(name = "Value")
private String value;
@Column(name = "Longi")
private String longi;
@Column(name = "Lat")
private String lat;
@Column(name = "Comments")
private String comments;
@Column(name = "GpsTime")
private String gpsTime;
@Column(name = "Timestamp")
private Timestamp timestamp;
@OneToMany(mappedBy = "speedemaill")
@JoinColumn(name = "ObjectId")
private Set<Highspeedd> highspeedd = new HashSet<Highspeedd>();
public Speedemaill() {
}
public Speedemaill(Integer id) {
this.id = id;
}
public Speedemaill(Integer id, Timestamp timestamp) {
this.id = id;
this.timestamp = timestamp;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getHeader() {
return header;
}
public void setHeader(String header) {
this.header = header;
}
public Integer getClientId() {
return clientId;
}
public void setClientId(Integer clientId) {
this.clientId = clientId;
}
public Integer getObjectId() {
return objectId;
}
public void setObjectId(Integer objectId) {
this.objectId = objectId;
}
public String getDisplay() {
return display;
}
public void setDisplay(String display) {
this.display = display;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public String getLongi() {
return longi;
}
public void setLongi(String longi) {
this.longi = longi;
}
public String getLat() {
return lat;
}
public void setLat(String lat) {
this.lat = lat;
}
public String getComments() {
return comments;
}
public void setComments(String comments) {
this.comments = comments;
}
public String getGpsTime() {
return gpsTime;
}
public void setGpsTime(String gpsTime) {
this.gpsTime = gpsTime;
}
public Date getTimestamp() {
return timestamp;
}
public void setTimestamp(Timestamp timestamp) {
this.timestamp = timestamp;
}
public Set<Highspeedd> getHighspeedd() {
return highspeedd;
}
public void addHighspeedd(Highspeedd highspeedd) {
highspeedd.setSpeeddemaill(this);
getHighspeedd().add(highspeedd);
}
@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Speedemaill)) {
return false;
}
Speedemaill other = (Speedemaill) object;
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false;
}
return true;
}
@Override
public String toString() {
return "pip.Speedemaill[id=" + id + "]";
}
}
Highspeedd.java
Code:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package pip;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
/**
*
* @author baktha
*/
@Entity
@Table(name = "highspeedd")
//@NamedQueries({@NamedQuery(name = "Highspeedd.findAll", query = "SELECT h FROM Highspeedd h"), @NamedQuery(name = "Highspeedd.findById", query = "SELECT h FROM Highspeedd h WHERE h.id = :id"), @NamedQuery(name = "Highspeedd.findByObjectId", query = "SELECT h FROM Highspeedd h WHERE h.objectId = :objectId"), @NamedQuery(name = "Highspeedd.findByClientId", query = "SELECT h FROM Highspeedd h WHERE h.clientId = :clientId"), @NamedQuery(name = "Highspeedd.findByDisplayName", query = "SELECT h FROM Highspeedd h WHERE h.displayName = :displayName"), @NamedQuery(name = "Highspeedd.findBySpeed", query = "SELECT h FROM Highspeedd h WHERE h.speed = :speed"), @NamedQuery(name = "Highspeedd.findByAlertType", query = "SELECT h FROM Highspeedd h WHERE h.alertType = :alertType"), @NamedQuery(name = "Highspeedd.findByFromTime", query = "SELECT h FROM Highspeedd h WHERE h.fromTime = :fromTime"), @NamedQuery(name = "Highspeedd.findByToTime", query = "SELECT h FROM Highspeedd h WHERE h.toTime = :toTime"), @NamedQuery(name = "Highspeedd.findByStatus", query = "SELECT h FROM Highspeedd h WHERE h.status = :status"), @NamedQuery(name = "Highspeedd.findByTimestamp", query = "SELECT h FROM Highspeedd h WHERE h.timestamp = :timestamp")})
public class Highspeedd implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "ID")
private Integer id;
@Column(name="ObjectId")
private Integer objectId;
@Column(name = "ClientId")
private Integer clientId;
@Column(name = "DisplayName")
private String displayName;
@Column(name = "Speed")
private Integer speed;
@Column(name = "AlertType")
private String alertType;
@Column(name = "FromTime")
private int fromTime;
@Column(name = "ToTime")
private String toTime;
@Column(name = "Status")
private String status;
@Column(name = "Timestamp")
private Timestamp timestamp;
@ManyToOne (fetch = FetchType.LAZY)
@JoinColumn(name = "ObjectId", nullable = false, insertable = false, updatable = false)
private Speedemaill speedemaill;
public Highspeedd() {
}
public Highspeedd(Integer id) {
this.id = id;
}
public Highspeedd(Integer id, Timestamp timestamp) {
this.id = id;
this.timestamp = timestamp;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getObjectId() {
return objectId;
}
public void setObjectId(Integer objectId) {
this.objectId = objectId;
}
public Integer getClientId() {
return clientId;
}
public void setClientId(Integer clientId) {
this.clientId = clientId;
}
public String getDisplayName() {
return displayName;
}
public void setDisplayName(String displayName) {
this.displayName = displayName;
}
public Integer getSpeed() {
return speed;
}
public void setSpeed(Integer speed) {
this.speed = speed;
}
public String getAlertType() {
return alertType;
}
public void setAlertType(String alertType) {
this.alertType = alertType;
}
public int getFromTime() {
return fromTime;
}
public void setFromTime(int fromTime) {
this.fromTime = fromTime;
}
public String getToTime() {
return toTime;
}
public void setToTime(String toTime) {
this.toTime = toTime;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public Timestamp getTimestamp() {
return timestamp;
}
public void setTimestamp(Timestamp timestamp) {
this.timestamp = timestamp;
}
public void setSpeeddemaill(Speedemaill speedemaill) {
this.speedemaill = speedemaill;
}
public Speedemaill getSpeeddemaill() {
return speedemaill;
}
@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Highspeedd)) {
return false;
}
Highspeedd other = (Highspeedd) object;
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false;
}
return true;
}
@Override
public String toString() {
return "pip.Highspeedd[id=" + id + "]";
}
}
the main class
Code:
Iterator query1 = session.createQuery("from Speedemaill speed join speed.highspeedd Highspeedd where speed.objectId = '"+ObjectId+"'").list().iterator();
the sql output
Code:
select
speedemail0_.ID as ID7_0_,
highspeedd1_.ID as ID8_1_,
speedemail0_.ClientId as ClientId7_0_,
speedemail0_.Comments as Comments7_0_,
speedemail0_.Display as Display7_0_,
speedemail0_.GpsTime as GpsTime7_0_,
speedemail0_.Header as Header7_0_,
speedemail0_.Lat as Lat7_0_,
speedemail0_.Longi as Longi7_0_,
speedemail0_.ObjectId as ObjectId7_0_,
speedemail0_.Timestamp as Timestamp7_0_,
speedemail0_.Value as Value7_0_,
highspeedd1_.AlertType as AlertType8_1_,
highspeedd1_.ClientId as ClientId8_1_,
highspeedd1_.DisplayName as DisplayN4_8_1_,
highspeedd1_.FromTime as FromTime8_1_,
highspeedd1_.ObjectId as ObjectId8_1_,
highspeedd1_.Speed as Speed8_1_,
highspeedd1_.Status as Status8_1_,
highspeedd1_.Timestamp as Timestamp8_1_,
highspeedd1_.ToTime as ToTime8_1_
from
speedemaill speedemail0_
inner join
highspeedd highspeedd1_
on speedemail0_.ID=highspeedd1_.ObjectId
where
speedemail0_.ObjectId='18'
I need this type of sql output
Code:
select
speedemail0_.ID as ID7_0_,
highspeedd1_.ID as ID8_1_,
speedemail0_.ClientId as ClientId7_0_,
speedemail0_.Comments as Comments7_0_,
speedemail0_.Display as Display7_0_,
speedemail0_.GpsTime as GpsTime7_0_,
speedemail0_.Header as Header7_0_,
speedemail0_.Lat as Lat7_0_,
speedemail0_.Longi as Longi7_0_,
speedemail0_.ObjectId as ObjectId7_0_,
speedemail0_.Timestamp as Timestamp7_0_,
speedemail0_.Value as Value7_0_,
highspeedd1_.AlertType as AlertType8_1_,
highspeedd1_.ClientId as ClientId8_1_,
highspeedd1_.DisplayName as DisplayN4_8_1_,
highspeedd1_.FromTime as FromTime8_1_,
highspeedd1_.ObjectId as ObjectId8_1_,
highspeedd1_.Speed as Speed8_1_,
highspeedd1_.Status as Status8_1_,
highspeedd1_.Timestamp as Timestamp8_1_,
highspeedd1_.ToTime as ToTime8_1_
from
speedemaill speedemail0_
inner join
highspeedd highspeedd1_
[color=#000000] on speedemail0_.ObjectId=highspeedd1_.ObjectId [/color]
where
speedemail0_.ObjectId='18'
please help how to do this one,
thanks in advance