Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Retrieving data from a resultset with two or more same column names.
Retrieving data from a resultset with two or more same column names. [message #1007904] Fri, 08 February 2013 00:52 Go to next message
cerh Mising name is currently offline cerh Mising name
Messages: 6
Registered: November 2011
Junior Member
@Entity
public T1{
	@Id
	@Column(name="id")
	int id;
	
	@Column(name="name")
	String name;
	
	@JoinColumn(name = "parentId")
	@OneToOne()
	T1 parentT1;	
}


The generated sql:
SELECT t1.id, t1.name, t0.id, t0.name FROM T1 t0, T1 t1 WHERE (t0.id = t1.parentDiv)
returns the correct data,
for exapmle
t1.id=1 t1.name=name1 t0.id=0 t0.name=name0
but the object of T1 has next values id=parentT1.id=1 and name=parentT1.name=name1.
Re: Retrieving data from a resultset with two or more same column names. [message #1007952 is a reply to message #1007904] Fri, 08 February 2013 07:47 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris Delahunt
Messages: 995
Registered: July 2009
Senior Member
What version of Eclipselink are you using and how are you creating and executing the query? EclipseLink should use positional references, not the names when building the object, so I am not sure how this could happen.
Re: Retrieving data from a resultset with two or more same column names. [message #1007961 is a reply to message #1007952] Fri, 08 February 2013 08:57 Go to previous message
cerh Mising name is currently offline cerh Mising name
Messages: 6
Registered: November 2011
Junior Member
I'm sorry that did not wrote a complete example.
This example gives an incorrect result if I uncomment //cq.multiselect(select);


Eclipselink 2.3.0 and 2.4.1

@Entity
public class T1{
	@Id
	@Column(name = "id")
	public String id;
		
	@Column(name = "NAME")
	public String name;
		
	@JoinColumn(name = "PARENT_id")
	@OneToOne(fetch = FetchType.EAGER)
	public T1 parentT1;	
}


CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<?> cq = cb.createQuery(T1.class);
Root<?> root = cq.from(T1.class);
Selection<?>[] select = new Selection[]{root.get("id"),root.get("name"),root.get("parentT1").get("id"),root.get("parentT1").get("name")};
//cq.multiselect(select);  <-----  ok if comment 
Query query = em.createQuery(cq);
((org.eclipse.persistence.jpa.JpaQuery<?>)query).getDatabaseQuery().dontMaintainCache();
List<T1> listT1=query.getResultList();
for (T1 t12 : listT1) {
 System.out.println(t12.id+" "+t12.name+" "+t12.parentT1.id+" "+t12.parentT1.name);			
}

[Updated on: Fri, 08 February 2013 08:59]

Report message to a moderator

Previous Topic:@Index with an@ElementCollection
Next Topic:Alert that DCN Took Place
Goto Forum:
  


Current Time: Sun Apr 20 09:39:44 EDT 2014

Powered by FUDForum. Page generated in 0.01445 seconds