i have 2 tables
Speedemaill.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.FetchType;
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.OneToOne;
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.AUTO)
@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", fetch = FetchType.LAZY)
@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.setSpeedemaill(this);
getHighspeedd().add(highspeedd);
}
public void setHighspeedd(Set<Highspeedd> highspedd) {
this.highspeedd = 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.CascadeType;
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.Table;
/**
*
* @author baktha
*/
@Entity
@Table(name = "highspeedd")
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 setSpeedemaill(Speedemaill speedemaill) {
this.speedemaill = speedemaill;
}
public Speedemaill getSpeedemaill() {
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 + "]";
}
}
main file
Code:
Iterator query1 = session.createQuery("from Speedemaill speed join speed.highspeedd Highspeedd where speed.objectId = '"+ObjectId+"'").list().iterator();
i got the following output
Code:
select
speedemail0_.ID as ID8_0_,
highspeedd1_.ID as ID9_1_,
speedemail0_.ClientId as ClientId8_0_,
speedemail0_.Comments as Comments8_0_,
speedemail0_.Display as Display8_0_,
speedemail0_.GpsTime as GpsTime8_0_,
speedemail0_.Header as Header8_0_,
speedemail0_.Lat as Lat8_0_,
speedemail0_.Longi as Longi8_0_,
speedemail0_.ObjectId as ObjectId8_0_,
speedemail0_.Timestamp as Timestamp8_0_,
speedemail0_.Value as Value8_0_,
highspeedd1_.AlertType as AlertType9_1_,
highspeedd1_.ClientId as ClientId9_1_,
highspeedd1_.DisplayName as DisplayN4_9_1_,
highspeedd1_.FromTime as FromTime9_1_,
highspeedd1_.ObjectId as ObjectId9_1_,
highspeedd1_.Speed as Speed9_1_,
highspeedd1_.Status as Status9_1_,
highspeedd1_.Timestamp as Timestamp9_1_,
highspeedd1_.ToTime as ToTime9_1_
from
speedemaill speedemail0_
inner join
highspeedd highspeedd1_
on speedemail0_.ID=highspeedd1_.ObjectId
where
speedemail0_.ObjectId='18'
but I need
same query but
Code:
inner join
highspeedd highspeedd1_
on speedemail0_ObjectId=highspeedd1_.ObjectId
please help me
what will i change to get the above output
Thanks in advance