Wrong query generated
monkeyden Nov 7, 2006 8:16 PMFor some reason, the resulting query from this entity has the ACTUAL DB field names for a couple of the non-pk fields (see SEQ_NUMBER, LAST_UPDATE). Can anyone give a hint as to what might be the problem? Thanks.
Query
select streetwatc0_.userKey as userKey1292_, streetwatc0_.locationId as locationId1292_, streetwatc0_.areaId as areaId1292_, streetwatc0_.addressStandardized as addressS4_1292_, streetwatc0_.SEQ_NUMBER as SEQ5_1292_, streetwatc0_.LAST_UPDATE as LAST6_1292_, streetwatc0_.ADDRESS as ADDRESS1292_ from DWL_STREET_WATCH_LIST streetwatc0_ where streetwatc0_.userKey=?
Client code
Query query = em.createQuery("from StreetWatchEntity where userKey = :userKey");
query.setParameter("userKey", userKey);
entities = query.getResultList();Entity
package com.company.project.entity;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import org.jboss.seam.annotations.Name;
@NamedQuery(
name="orderedStreets",
query="from StreetWatchEntity order by seqNumber"
)
@Entity
@Name("streetWatchEntity")
@Table(name = "STREET_WATCH_LIST")
@IdClass(StreetWatchPK.class)
public class StreetWatchEntity implements java.io.Serializable {
private static final long serialVersionUID = 4855048029589330487L;
public StreetWatchEntity(){}
public StreetWatchEntity(Long userKey, Long locationId, String address, String addressStandardized, Date lastUpdate, Long seqNumber, Long areaId) {
this.userKey = userKey;
this.locationId = locationId;
this.address = address;
this.addressStandardized = addressStandardized;
this.lastUpdate = lastUpdate;
this.seqNumber = seqNumber;
this.areaId = areaId;
}
/**
* Retrieves the UserKey from the entity
*/
@Id
@Column(name = "USER_KEY", length = 22, nullable = false)
public Long getUserKey() {
return this.userKey;
}
/**
* Sets the UserKey of the entity
*/
public void setUserKey(Long userKey) {
this.userKey = userKey;
}
/**
* Retrieves the LocationId from the entity
*/
@Id
@Column(name = "LOCATION_ID", length = 19, nullable = false)
public Long getLocationId() {
return this.locationId;
}
/**
* Sets the LocationId of the entity
*/
public void setLocationId(Long locationId) {
this.locationId = locationId;
}
/**
* Retrieves the AddressStandardized from the entity
*/
@Id
@Column(name = "ADDRESS_STANDARDIZED", length = 128, nullable = false)
public String getAddressStandardized() {
return this.addressStandardized;
}
/**
* Sets the AddressStandardized of the entity
*/
public void setAddressStandardized(String addressStandardized) {
this.addressStandardized = addressStandardized;
}
/**
* Retrieves the AreaId from the entity
*/
@Id
@Column(name = "AREA_ID", length = 22, nullable = false)
public Long getAreaId() {
return this.areaId;
}
/**
* Sets the AreaId of the entity
*/
public void setAreaId(Long areaId) {
this.areaId = areaId;
}
/**
* Retrieves the Address from the entity
*/
@Column(name = "ADDRESS", length = 128, nullable = true)
public String getAddress() {
return this.address;
}
/**
* Sets the Address of the entity
*/
public void setAddress(String address) {
this.address = address;
}
/**
* Retrieves the LastUpdate from the entity
*/
@Column(name = "LAST_UPDATE", length = 7, nullable = true)
public Date getLastUpdate() {
return this.lastUpdate;
}
/**
* Sets the LastUpdate of the entity
*/
public void setLastUpdate(Date lastUpdate) {
this.lastUpdate = lastUpdate;
}
/**
* Retrieves the SeqNumber from the entity
*/
@Column(name = "SEQ_NUMBER", length = 22, nullable = false)
public Long getSeqNumber() {
return this.seqNumber;
}
/**
* Sets the SeqNumber of the entity
*/
public void setSeqNumber(Long seqNumber) {
this.seqNumber = seqNumber;
}
private String address = null;
private String addressStandardized = null;
private Long areaId = null;
private Date lastUpdate = null;
private Long locationId = null;
private Long seqNumber = null;
private Long userKey = null;
}PK Class
package com.company.project.entity;
import java.io.Serializable;
public class StreetWatchPK implements Serializable{
private static final long serialVersionUID = 3355389391459690610L;
private Long userKey = null;
private Long locationId = null;
private String addressStandardized = null;
private Long areaId = null;
/**
* No-arg constructor
*/
public StreetWatchPK( ) {}
/**
* All-fields constructor
* @param userKey
* @param locationId
* @param addressStandardized
* @param areaId
*/
public StreetWatchPK(Long userKey, Long locationId, String addressStandardized, Long areaId) {
this.userKey = userKey;
this.locationId = locationId;
this.addressStandardized = addressStandardized;
this.areaId = areaId;
}
public boolean equals(Object obj) {
if (obj == this)
return true;
if (!(obj instanceof StreetWatchPK))
return false;
StreetWatchPK pk = (StreetWatchPK) obj;
//User Key
if(locationId.longValue() != pk.getLocationId().longValue()){
return false;
}
//Location Id
if(userKey.longValue() != pk.getUserKey().longValue()){
return false;
}
//Area Id
if(areaId.longValue() != pk.getAreaId().longValue()){
return false;
}
if (!addressStandardized.equals(pk.addressStandardized)){
return false;
}
return true;
}
public int hashCode() {
return addressStandardized.hashCode() +
(int)areaId.longValue() +
(int)locationId.longValue() +
(int)userKey.longValue();
}
/**
* @return the addressStandardized
*/
public String getAddressStandardized() {
return addressStandardized;
}
/**
* @param addressStandardized the addressStandardized to set
*/
public void setAddressStandardized(String addressStandardized) {
this.addressStandardized = addressStandardized;
}
/**
* @return the areaId
*/
public Long getAreaId() {
return areaId;
}
/**
* @param areaId the areaId to set
*/
public void setAreaId(Long areaId) {
this.areaId = areaId;
}
/**
* @return the locationId
*/
public Long getLocationId() {
return locationId;
}
/**
* @param locationId the locationId to set
*/
public void setLocationId(Long locationId) {
this.locationId = locationId;
}
/**
* @return the userKey
*/
public Long getUserKey() {
return userKey;
}
/**
* @param userKey the userKey to set
*/
public void setUserKey(Long userKey) {
this.userKey = userKey;
}
}