EntityManager's createQuery question [message #899860] |
Thu, 02 August 2012 16:09 |
|
Hi everybody,
I'm new at JPA, so maybe its the way I'm trying or something like that. I need some help to understand if it is a programmer problem or JPA problem.
I create dynamically this query:
select distinct o from DonglePoint o where o.donglePointPK.chassis = :chassis and o.donglePointPK.timestamp between :timestamp1 and :timestamp2 order by o.donglePointPK.timestamp
Right after I do:
final Query query = this.entityManager.createQuery(filter);
Where "filter" is a String with the content of the code above.
I get this query generated by JPA:
EJBQueryImpl(ReadAllQuery(referenceClass=DonglePoint sql="SELECT DISTINCT HEADING, PLACA, VELOCIDADE, TIMESTAMP, NUM_CHASSIS, NR_LAT, NR_LNG, TIMESTAMP FROM VEICULO_POSICAO_DONGLE WHERE ((NUM_CHASSIS = ?) AND (TIMESTAMP BETWEEN ? AND ?)) ORDER BY TIMESTAMP ASC"))
If you look close to the query you will see two TIMESTAMP. After that, it's understandable that I get "Ambiguous".
This are the object that compounds my DonglePoint class:
DonglePoint Class
@Entity
@NamedQuery(name = "findDonglePointsWithinRange", query = "SELECT dp FROM DonglePoint dp WHERE dp.donglePointPK.chassis = :chassis and dp.donglePointPK.timestamp BETWEEN :ini AND :final order by dp.donglePointPK.timestamp")
@Table(name = "VEICULO_POSICAO_DONGLE")
public class DonglePoint implements Serializable {
private static final long serialVersionUID = -7456971713605400889L;
public static final int LAT_LNG_SCALE = 6;
public static final int CHASSIS_LENGTH = 17;
public static final int PLATE_LENGTH = 10;
public static final int SPEED_PRECISION = 9;
public static final int HEADING_PRECISION = 9;
@Column(name = "HEADING", length = DonglePoint.HEADING_PRECISION)
private BigDecimal heading;
@Embedded
private Position position;
@EmbeddedId
private DonglePointPK donglePointPK;
@Column(name = "PLACA", nullable = false, length = DonglePoint.PLATE_LENGTH)
private String plate;
@Column(name = "VELOCIDADE", length = DonglePoint.SPEED_PRECISION)
private BigDecimal speed;
public DonglePoint() {
super();
this.position = new Position();
this.donglePointPK = new DonglePointPK();
}
/* GETs and SETs */
}
Position Class
@Embeddable
public class Position {
public static final int LATITUDE = 1;
public static final int LONGITUDE = 2;
public static final int LATITUDE_PRECISION = 9;
public static final int LONGITUDE_PRECISION = 9;
@Column(name = "NR_LAT", precision = Position.LATITUDE_PRECISION)
private String latitude;
@Column(name = "NR_LNG", precision = Position.LONGITUDE_PRECISION)
private String longitude;
public Position() {
super();
}
public Position(final Position position) {
super();
this.latitude = position.getLatitude();
this.longitude = position.getLongitude();
}
public Position(final BigDecimal latitude, final BigDecimal longitude) throws NullPointerException {
this.latitude = latitude.toString();
this.longitude = longitude.toString();
}
public Position(final String latitude, final String longitude) {
this.latitude = latitude;
this.longitude = longitude;
}
/* GETs and SETs */
}
DonglePointPK Class
@Embeddable
public class DonglePointPK implements Serializable {
private static final long serialVersionUID = 5093736875260224632L;
@Column(name = "NUM_CHASSIS", nullable = false, length = DonglePoint.CHASSIS_LENGTH)
private String chassis;
@Column(name = "TIMESTAMP", nullable = false)
private Timestamp timestamp;
/* GETs and SETs */
}
The three wierdest parts are:
1 - If I remove from the query "order by o.donglePointPK.timestamp", there is no duplication.
2 - If I run a NamedQuery see "findDonglePointsWithinRange" in DonglePoint Class, there is no duplication.
3 - If it's a simple attribute from the classe (not an object), there is no duplication.
Did anyone ever see something like that? Is it a problem from JPA or am I doing something that I wasn't supposed to do?
Thanks from helpin' me out.
--
Eduardo Trzan
|
|
|
|
Re: EntityManager's createQuery question [message #900756 is a reply to message #900027] |
Wed, 08 August 2012 12:14 |
|
Hi Chris,
Thanks for responding!
The version is 2.3. I'm downloading the latest release to see if there is any problem. Yes, the only difference is the distinct clause, since I thought it wouldn't be the problem, I never tried. I will give a shot, maybe it could be the problem anyways.
I will try without the 'distinct' to see first, if it doesn't work I will try the latest version of EclipseLink with and without "distinct". Whatever the result, I will come to share it.
Thanks
--
Eduardo Trzan
|
|
|
Powered by
FUDForum. Page generated in 0.03358 seconds