Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Custom query to load list in bidirectional onetomany relationship
Custom query to load list in bidirectional onetomany relationship [message #1778092] Sat, 09 December 2017 19:06 Go to next message
Antonio Brea Mochales is currently offline Antonio Brea MochalesFriend
Messages: 1
Registered: December 2017
Junior Member
I have a bidirectional onetomany relationship in this entities: Actividad and TagVinculado
TagVinculado entity has ManyToOne relationship with Tag
Tag entity has ManyToOne relationship with Tipo

When I access to tagsVinculados list from actividad entity, eclipselink create this queries:
1 query for tag_vinculados and for each tagVicnulado in list generetes 1 query for Tag and 1 query for Tag.Tipo
SELECT * FROM tags_vinculados WHERE (idActividad = ?)
SELECT * FROM tags WHERE (id = ?)
SELECT * FROM tipos WHERE (id = ?)
...
SELECT * FROM tags WHERE (id = ?)
SELECT * FROM tipos WHERE (id = ?)


Exist any way to custom the queries to load this list?
I would load this list with single query with 2 joins:
select tagVinculado
from TagVinculado tagVinc
inner join fetch tagVinc.tag tag
inner join fetch tagVinc.tag.tipo tipoTag
where tagVinc.actividad.id = ?


@Entity
@Table(name = "actividades")
public class Actividad Serializable {

@Column(name = "nombre")
private String nombre;

@OneToMany(mappedBy = "actividad", fetch=FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
private List<TagVinculado> tagsVinculados;
}

@Entity
@Table(name = "tags_vinculados")
public class TagVinculado implements Serializable {

@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name = "idTag")
private Tag tag;

@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name = "idActividad")
private Actividad actividad;
}

@Entity
@Table(name = "tags")
public class Tag Serializable {

@Column(name = "nombre")
private String nombre;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "idTipo")
private Tipo tipo;
}

@Entity
@Table(name = "tipos")
public class Tipo Serializable {

@Column(name = "nombre")
private String nombre;
}
Re: Custom query to load list in bidirectional onetomany relationship [message #1778195 is a reply to message #1778092] Mon, 11 December 2017 18:02 Go to previous message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
Have you seen https://www.eclipse.org/eclipselink/documentation/2.5/solutions/performance001.htm#CHDEGCHH ?
Previous Topic:L2 cache coordination in Wildfly
Next Topic:Blocked - waiting to lock
Goto Forum:
  


Current Time: Fri Mar 29 07:34:33 GMT 2024

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

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

Back to the top