cancel
Showing results for 
Search instead for 
Did you mean: 

OneToMany relationship not working

Former Member
0 Kudos

Hi All!

I'm working on NetWeaver DS 7.1 SP 05 and have a project where I have two entities with a OneToMany - ManyToOne relationship and an EJB method that queries the first entity with a namedquery that make a join with the second entity. Whenever I run the EJB method got a time out from the server.

Trying to figure out the problem I took out the relationship between the entities and change the namedquery for a native query and the application works.

Can someone tell me what am i doing wrong? The database server is DB2.

These are the entities:

First entity.

@NamedQueries( {

// @NamedQuery(name = "OrdenFabricacion.buscarPorLote", query = "SELECT DISTINCT ordFab FROM OrdenFabricacion ordFab JOIN ordFab.tbLoteCollection AS lote WHERE lote.pk.coLote = ?1"),

@NamedQuery(name = "OrdenFabricacion.buscarPorOrden", query = "SELECT DISTINCT ordFab FROM OrdenFabricacion ordFab WHERE ordFab.coOrdenfabricacion = ?1")

// @NamedQuery(name = "OrdenFabricacion.buscarPorLotePendientes", query = "SELECT DISTINCT ordFab FROM OrdenFabricacion ordFab JOIN ordFab.tbLoteCollection AS lote JOIN lote.tbOperacionloteCollection AS opLote WHERE opLote.pk.coLote = ?1 AND opLote.fhTerminacion IS NULL")

})

@Entity

@Table(name="TB_ORDENFABRICACION")

public class OrdenFabricacion implements Serializable {

@Id

@Column(name="CO_ORDENFABRICACION")

private String coOrdenfabricacion;

@Column(name="SW_TINTORERIA", nullable = true)

private String swTintoreria;

@Column(name="SW_PLANEACION")

private String swPlaneacion;

@Column(name="CA_KILOS", nullable = true)

private double caKilos;

@Column(name="FH_ACTUALIZACION")

@Temporal(TemporalType.TIMESTAMP)

private Timestamp fhActualizacion;

@Column(name="CA_NOTIFICADA", nullable = true)

private double caNotificada;

@Column(name="CA_PROGRAMADA")

private double caProgramada;

@Version

private int version;

@Column(name="CO_VERSIONFABRICACION", nullable = true)

private String coVersionfabricacion;

@Column(name="CA_PRIMERAS", nullable = true)

private double caPrimeras;

@Column(name="CO_CLIENTE", nullable = true)

private String coCliente;

@Column(name="CO_ALMACEN", nullable = true)

private String coAlmacen;

@Column(name="DE_COMPOSICION")

private String deComposicion;

@Column(name="CS_TANDA", nullable = true)

private int csTanda;

@Column(name="SW_SUMINISTROILIMITADO", nullable = true)

private String swSuministroilimitado;

@Column(name="FH_PROGRAMACION")

@Temporal(TemporalType.TIMESTAMP)

private Timestamp fhProgramacion;

@Column(name="DE_PROVEEDOR", nullable = true)

private String deProveedor;

@Column(name="CO_FORMULATINTORERIA", nullable = true)

private String coFormulatintoreria;

@Column(name="SW_ESTADO")

private String swEstado;

@Column(name="CO_USUARIO")

private String coUsuario;

@Column(name="CO_RESERVA", nullable = true)

private double coReserva;

@Column(name="FH_CREACION")

@Temporal(TemporalType.TIMESTAMP)

private Timestamp fhCreacion;

@Column(name="VL_PORCENTAJEEXCESO", nullable = true)

private double vlPorcentajeexceso;

@ManyToOne

@JoinColumn(name="CO_TIPOSEMIELABORADO", nullable = true)

private TipoSemiElaborado coTiposemielaborado;

@ManyToOne

@JoinColumn(name="CO_CENTRO")

private Centro coCentro;

@ManyToOne

@JoinColumn(name="CO_CATEGORIA", nullable = true)

private Categoria coCategoria;

@ManyToOne

@JoinColumn(name="CO_CLASEORDEN")

private ClaseOrden coClaseorden;

@ManyToOne

@JoinColumn(name="CO_MATERIALSEGUNDA", nullable = true)

private Material coMaterialsegunda;

@ManyToOne

@JoinColumn(name="CO_MATERIAL")

private Material coMaterial;

@ManyToOne

@JoinColumn(name="CO_UNIDAD")

private Unidad coUnidad;

@ManyToOne

@JoinColumn(name="CO_TALLASEGUNDA", nullable = true)

private Talla coTallasegunda;

@ManyToOne

@JoinColumn(name="CO_COLORSEGUNDA", nullable = true)

private Color coColorsegunda;

@ManyToOne

@JoinColumn(name="CO_TALLA")

private Talla coTalla;

@ManyToOne

@JoinColumn(name="CO_COLOR")

private Color coColor;

@OneToMany(mappedBy="coOrdenfabricacion", fetch=FetchType.LAZY)

private Set tbOperacionloteCollection) {

this.tbOperacionloteCollection = tbOperacionloteCollection;

}

@Embeddable

public static class PK implements Serializable {

@Column(name="CO_LOTE")

private String coLote;

@Column(name="CO_ORDENFABRICACION")

private String coOrdenfabricacion2;

private static final long serialVersionUID = 1L;

public PK() {

super();

}

public String getCoLote() {

return this.coLote;

}

public void setCoLote(String coLote) {

this.coLote = coLote;

}

public String getCoOrdenfabricacion2() {

return this.coOrdenfabricacion2;

}

public void setCoOrdenfabricacion2(String coOrdenfabricacion) {

this.coOrdenfabricacion2 = coOrdenfabricacion;

}

@Override

public boolean equals(Object o) {

if (o == this) {

return true;

}

if ( ! (o instanceof PK)) {

return false;

}

PK other = (PK) o;

return this.coLote.equals(other.coLote)

&& this.coOrdenfabricacion2.equals(other.coOrdenfabricacion2);

}

@Override

public int hashCode() {

return this.coLote.hashCode()

^ this.coOrdenfabricacion2.hashCode();

}

}

public OrdenFabricacion getCoOrdenfabricacion() {

return coOrdenfabricacion;

}

public void setCoOrdenfabricacion(OrdenFabricacion coOrdenfabricacion) {

this.coOrdenfabricacion = coOrdenfabricacion;

}

}

EJB Method

public List findNamedQuery(String namedQuery, Parametro parametro) {

Query query = entityManager.createNamedQuery(namedQuery);

setParametros(query, parametro);

return query.getResultList();

}

Edited by: José Fernando Arango Jimenez on Jul 3, 2008 11:31 PM

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Timeout would be rather unusual. You seem to have a problem with the SQL that gets compiled from your JPQL named query. When you change the query to a native one you will most probably enter SQL that is understood by your database. Have you checked the default-trace for error-messages? They would be very helpful for further analysis. BTW: Do you use the system DataSource or a custom one? If the latter is true it would be interesting whether you use Open SQL or Native/Vendor SQL..

Best Regards,

Robin