Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Strage error with typedQuery

On Jueves 08 Septiembre 2011 10:01:33 James Sutherland escribió:

> The issue seems to be with your using TABLE_PER_CLASS (not SingleTable).

> Please log a bug with the details.

>

> What do you mean you don't get the error with 2.3.0? What doesn't work?

>

> You may wish to consider using a different inheritance type.

>

Thanks for the help. I can make a workaround changing the query parameter of Enum to String. Also, in eclipselink 2.3.0 the bug exist (the query return nothing when I expect something) but the exception dissapear.

> Arcangel wrote:

> > On Jueves 01 Septiembre 2011 13:58:40 usted escribió:

> >> The error seems to indicate that the Enum is being passed directly to

> >> the database without being converted.

> >>

> >> Setting, "eclipselink.logging.parameters"="true" in your persistence.xml

> >> will help debug, then it will print the parameters.

> >>

> >> I'm not sure how the value could be missed being converted. What type

> >> is used for the column in the table?

> >

> > After some debugging I can verify the strange behavior. The TypedQuery

> > call

> > two sql querys. In the first, the parameter tipoDevolucion is String and

> > in

> > the second query the parameter tipoDevolucion is TipoDevolucion. I think

> > this

> > is a bug in eclipselink when you use inheretance SingleTable with some

> > Entity

> > that have Enumerated.String field. With eclipselink 2.3.0 not exception

> > is throw, but the query won't work.

> >

> >> Arcangel wrote:

> >> > Hello.

> >> >

> >> > I'm having some troubles with a query:

> >> > ----------------

> >> > CriteriaQuery<DetalleDevolucion> criteriaQuery =

> >> > cb.createQuery(DetalleDevolucion.class);

> >> >

> >> > Root<DetalleDevolucion> from =

> >> > criteriaQuery.from(DetalleDevolucion.class);

> >> >

> >> > Predicate predicate =

> >> > cb.equal(from.get(DetalleDevolucion_.tipoSorteo), tipoSorteo);

> >> >

> >> > predicate = cb.and(predicate,

> >> > cb.equal(from.get(DetalleDevolucion_.noSorteo),

> >> > Integer.valueOf(noSorteo)));

> >> >

> >> > predicate = cb.and(predicate,

> >> > cb.equal(from.get(DetalleDevolucion_.tipoDevolucion),

> >> > TipoDevolucion.valueOf(tipoDevolucion)));

> >> >

> >> > criteriaQuery.where(predicate);

> >> >

> >> > TypedQuery<DetalleDevolucion> typedQuery =

> >>

> >> em.createQuery(criteriaQuery);

> >>

> >> > return typedQuery.getResultList();

> >> > ------------------

> >> > When I do that I obtain:

> >> > ----------------

> >> > Exception [EclipseLink-4002] (Eclipse Persistence Services -

> >> > 2.2.0.v20110202-

> >> > r8913): org.eclipse.persistence.exceptions.DatabaseException

> >> > Internal Exception: java.sql.SQLException: El tipo no está soportado.

> >> > Error Code: 20000

> >> > Call: SELECT NOSERIE, NOBILLETE, NOSORTEO, SIGNO, TIPOSORTEO,

> >>

> >> NOFRACCION,

> >>

> >> > AUDITUSER, CONSECUTIVO, DEVOLUCION, FRACCIONES, NOCORTE,

> >> > OBSERVACIONES, TIPODEVOLUCION, VERSION FROM DetallesDevolucionAcum

> >> > WHERE

> >>

> >> (((((TIPOSORTEO

> >>

> >> > = ?)

> >> > AND (NOSORTEO = ?)) AND (TIPODEVOLUCION = ?)) AND (NOCORTE = ?)) AND

> >> > (FRACCIONES = ?))

> >> > bind => [5 parameters bound]

> >> > --------------

> >> >

> >> > if I comment this part:

> >> > ------------

> >> > predicate = cb.and(predicate,

> >> > cb.equal(from.get(DetalleDevolucion_.tipoDevolucion),

> >> > TipoDevolucion.valueOf(tipoDevolucion)));

> >> > ----------

> >> > The query works fine.

> >> >

> >> >

> >> > My entity is declared this way:

> >> > -----------------

> >> > @Entity

> >> > @Table(name="DetallesDevoluciones")

> >> > @IdClass(FraccionPK.class)

> >> > @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)

> >> > public class DetalleDevolucion extends Model {

> >> >

> >> > @Id

> >> > @NotEmpty(message="El tipo de sorteo no puede estar vacio.")

> >> > @Pattern(regexp="[A-Z]{2}", message="El tipo de sorteo deben ser 2

> >> >

> >> > letras mayúsculas.")

> >> >

> >> > private String tipoSorteo;

> >> >

> >> > @Id

> >> > @NotNull(message="El consecutivo no puede estar vacio.")

> >> > @Range(min=0, max=9999, message="El valor del no de Sorteo debe estar

> >> >

> >> > entre 0 y 9999")

> >> >

> >> > private Integer noSorteo;

> >> >

> >> > @NotNull(message="El consecutivo no puede estar vacio.")

> >> > @Range(min=0, max=99, message="El valor del consecutivo debe estar

> >> >

> >> > entre 0 y 99")

> >> >

> >> > private Integer consecutivo;

> >> >

> >> > @NotNull(message="La cantidad de devolución no puede estar vacia.")

> >> > @Digits(integer=14, fraction=2, message="El devolución inútil es

> >> > mayor

> >> >

> >> > al máximo predeterminado")

> >> >

> >> > @Column(precision = 14, scale = 2)

> >> > private BigDecimal devolucion;

> >> >

> >> > @NotNull(message="Las fracciones no pueden estar vacias.")

> >> > private Integer fracciones;

> >> >

> >> > @Id

> >> > @NotNull(message="El No de Billete no puede estar vacio.")

> >> > @Range(min=0, max=9999999, message="El valor del no de billete debe

> >> >

> >> > estar entre 0 y 9999999")

> >> >

> >> > private Integer noBillete;

> >> >

> >> > @Id

> >> > @NotNull(message="El signo no puede estar vacio.")

> >> > @Range(min=0, max=12, message="El valor del signo debe estar entre 0

> >> > y

> >> >

> >> > 12")

> >> >

> >> > private Integer signo;

> >> >

> >> > @Id

> >> > @NotNull(message="La serie no puede estar vacia.")

> >> > @Range(min=1, max=9, message="El no de serie debe estar entre 1 y 9")

> >> > private Integer noSerie;

> >> >

> >> > @Id

> >> > @NotNull(message="El no de fracción no puede estar vacio.")

> >> > @Range(min=-99, max=99, message="El valor del no de fracción debe

> >> >

> >> > estar entre 0 y 99")

> >> >

> >> > private Integer noFraccion;

> >> >

> >> > @NotNull(message="El no de corte no puede estar vacio.")

> >> > @Index

> >> > @Column(name="NOCORTE")

> >> > private Integer noCorte;

> >> >

> >> > private String observaciones;

> >> >

> >> > @Enumerated(EnumType.STRING)

> >> > @NotNull(message="El tipo de devolución no puede estar vacio.")

> >> > @Index

> >> > @Column(name="TIPODEVOLUCION")

> >> > private TipoDevolucion tipoDevolucion;

> >> >

> >> > ...

> >> > }

> >> > ------------

> >> > And I have a child entity:

> >> > --------------

> >> > @Entity

> >> > @Table(name="DetallesDevolucionAcum")

> >> > public class DetalleDevolucionAcum extends DetalleDevolucion{

> >> >

> >> > private static final long serialVersionUID = 1893358673129186997L;

> >> >

> >> > }

> >> > ---------------

> >> >

> >> > Any Ideas?

> >> >

> >> > Thanks for your help.

>

> -----

> http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland

> http://www.eclipse.org/eclipselink/

> EclipseLink , http://www.oracle.com/technology/products/ias/toplink/

> TopLink

> Wiki: http://wiki.eclipse.org/EclipseLink EclipseLink ,

> http://wiki.oracle.com/page/TopLink TopLink

> Forums: http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink ,

> http://www.nabble.com/EclipseLink-f26430.html EclipseLink

> Book: http://en.wikibooks.org/wiki/Java_Persistence Java Persistence

> Blog: http://java-persistence-performance.blogspot.com/ Java Persistence

> Performance


--

I.S.C. José Arcángel Salazar Delgado

Gerente de I+D

Tel. oficina: 229-9-27-54-78

Attachment: signature.asc
Description: This is a digitally signed message part.


Back to the top