Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » EntityManager's createQuery question(EntityManager's creating query with ambiguous field)
icon1.gif  EntityManager's createQuery question [message #899860] Thu, 02 August 2012 16:09 Go to next message
Eduardo Gomes Trzan is currently offline Eduardo Gomes TrzanFriend
Messages: 2
Registered: August 2012
Location: Salvador, Bahia
Junior Member
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 #900027 is a reply to message #899860] Fri, 03 August 2012 13:47 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
What EclipseLink version are you using, and does it reproduce on the latest 2.4 release? The only difference I see between the named query and the JPQL one is the distinct clause - does your JPQL query have the issue if you remove the 'distinct' from it? It doesn't seem neccesary for the query results since the entity should be unique anyway.

This looks like it should work though, so please file a bug if it still reproduces on the latest version.

Thanks,
Chris
Re: EntityManager's createQuery question [message #900756 is a reply to message #900027] Wed, 08 August 2012 12:14 Go to previous message
Eduardo Gomes Trzan is currently offline Eduardo Gomes TrzanFriend
Messages: 2
Registered: August 2012
Location: Salvador, Bahia
Junior Member
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
Previous Topic:EclipseLink + Foxpro
Next Topic:Entity Isolation Level
Goto Forum:
  


Current Time: Fri Apr 19 22:22:45 GMT 2024

Powered by FUDForum. Page generated in 0.03358 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top