Cómo pedir una tabla OneToMany join en criterios de hibernación
Digamos que tengo una madre de clase con un mapeo OneToMany a Gatitos
@Entity
@org.hibernate.annotations.Entity(dynamicUpdate = true)
@Table(name = "Mother")
.....
@OneToMany(fetch = FetchType.LAZY, targetEntity=Kittens.class, cascade=CascadeType.ALL)
@JoinColumn(name="motherId")
private List<Kittens> kittens;
Estoy utilizando la Api de criterios para proporcionar una lista
Criteria criteria = this.getSession().createCriteria(Mother.class);
Criterion MotherType = Restrictions.eq("type", "domesticated");
criteria.add(MotherType)
.addOrder(Order.asc("motherName"))
.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)
.setFetchMode("kittens", FetchMode.JOIN)
// .addOrder(Order.asc("kittens.kittenName"));
List test = criteria.list();
Funciona bien hasta que intento agregar el orden de los gatitos campo kittenName
También he intentado agregar la anotación @OrderBy(value="kittenName") bajo el Kitten @OneToMany(...etc) que funciona bien hasta que utilice la API de criterios y este orden precederá a cualquier otra instrucción de orden en el sql.
Saludos por adelantado para cualquier ayudar...
34
1 answers
Es necesario añadir la @javax.persistence.OrderBy
anotación a su lista kittens
.
@OneToMany(fetch = FetchType.LAZY,
targetEntity=Kittens.class,
cascade=CascadeType.ALL)
@JoinColumn(name="motherId")
@OrderBy("kittenName")
private List<Kittens> kittens;
@ Ver
- Hibernate Annotations Reference Guide
- Capítulo 2.2.5. Mapeo de asociaciones/relaciones de entidades
- Subcapítulo 2.2.5.3.4. Colecciones indexadas (Lista, Mapa)
63
Author: Ralph,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-04-06 05:35:37
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-04-06 05:35:37