Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » [SOLVED] misunderstanding annotations(Trying to do a very simply ManyToOne annotation but failing)
icon4.gif  [SOLVED] misunderstanding annotations [message #941221] Fri, 12 October 2012 10:02 Go to next message
FiruzzZ Mising name is currently offline FiruzzZ Mising nameFriend
Messages: 19
Registered: October 2011
Junior Member
I can't figure it out why Eclipselink is expecting a bytea instead of a integer.

@Entity
NotaCrecitoProveedor

//part of the entity
    @Basic(optional = false)
    @ManyToOne(optional = false)
    @JoinColumn(name = "usuario", nullable = false)
    private Usuario usuario;
    @Basic(optional = false)
    @JoinColumn(name = "proveedor", referencedColumnName="id", nullable = false)
    @ManyToOne(optional = false)
    private Proveedor proveedor;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "notaCreditoProveedor", orphanRemoval = true)
    private List<DetalleNotaCreditoProveedor> detalleNotaCreditoProveedorList;



if I execute this JPQL:
return (NotaCreditoProveedor) getEntityManager().createQuery("SELECT o FROM NotaCreditoProveedor o WHERE o.numero = " + numero + " AND o.proveedor.id=" + proveedor.getId()).getSingleResult();


I got this Exception
Exception Description: Invalid query key [id] in expression.
Local Exception Stack: 
Exception [EclipseLink-6015] (Eclipse Persistence Services - 2.2.1.v20110722-r9776): org.eclipse.persistence.exceptions.QueryException
Exception Description: Invalid query key [id] in expression.
	at org.eclipse.persistence.exceptions.QueryException.invalidQueryKeyInExpression(QueryException.java:658)
	at org.eclipse.persistence.internal.expressions.QueryKeyExpression.getQueryKeyOrNull(QueryKeyExpression.java:469)
	at org.eclipse.persistence.internal.expressions.QueryKeyExpression.isAttribute(QueryKeyExpression.java:538)
	at org.eclipse.persistence.internal.expressions.RelationExpression.isObjectComparison(RelationExpression.java:449)
	at org.eclipse.persistence.internal.expressions.RelationExpression.normalize(RelationExpression.java:517)
	at org.eclipse.persistence.internal.expressions.CompoundExpression.normalize(CompoundExpression.java:226)



AND i if try to persist a NotaCreditoProveedor throws:

Call: INSERT INTO nota_credito_proveedor (ANULADA, DESACREDITADO, fecha_nota_credito_proveedor, GRAVADO, IMPORTE, impuestos_recuperables, IVA10, IVA21, no_gravado, NUMERO, OBSERVACION, PROVEEDOR, USUARIO, remesa) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
	bind => [14 parameters bound]
Query: InsertObjectQuery(NotaCreditoProveedor{id=null, numero=100000001, anulada=false, desacreditado=null, fechaCarga=null, fechaNotaCreditoProveedor=Sun Jan 01 00:00:00 ART 2012, gravado=0.00, importe=0.99, impuestosRecuperables=0.00, iva10=0.00, iva21=0.00, noGravado=0.99, observacion=null, usuario=admin, proveedor=CLIENTECITO, detalleNotaCreditoProveedorList=[DetalleNotaCreditoProveedor{id=null, cantidad=1, precioUnitario=0.99, producto=Producto{id=4, codigo=p00, nombre=p00, stockmaximo=0, stockactual=-1019, stockminimo=0, deposito=null, ubicacion=null, costoCompra=0.0, descripcion=null, updatePrecioVenta=false, precioVenta=0.0, remunerativo=true, fechaAlta=Tue Oct 02 16:35:17 ART 2012, ultimaCompra=null, iva=0.0, marca=MARCA..., rubro=Un Rubro, subrubro=null, idunidadmedida=UNITARIO}}]})
javax.persistence.RollbackException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.2.1.v20110722-r9776): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.postgresql.util.PSQLException: ERROR: la columna «proveedor» es de tipo integer pero la expresión es de tipo bytea
  Hint: Necesitará reescribir la expresión o aplicarle una conversión de tipo.
  Position: 262
Error Code: 0
Call: INSERT INTO nota_credito_proveedor (ANULADA, DESACREDITADO, fecha_nota_credito_proveedor, GRAVADO, IMPORTE, impuestos_recuperables, IVA10, IVA21, no_gravado, NUMERO, OBSERVACION, PROVEEDOR, USUARIO, remesa) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
	bind => [14 parameters bound]
Query: InsertObjectQuery(NotaCreditoProveedor{id=null, numero=100000001, anulada=false, desacreditado=null, fechaCarga=null, fechaNotaCreditoProveedor=Sun Jan 01 00:00:00 ART 2012, gravado=0.00, importe=0.99, impuestosRecuperables=0.00, iva10=0.00, iva21=0.00, noGravado=0.99, observacion=null, usuario=admin, proveedor=CLIENTECITO, detalleNotaCreditoProveedorList=[DetalleNotaCreditoProveedor{id=null, cantidad=1, precioUnitario=0.99, producto=Producto{id=4, codigo=p00, nombre=p00, stockmaximo=0, stockactual=-1019, stockminimo=0, deposito=null, ubicacion=null, costoCompra=0.0, descripcion=null, updatePrecioVenta=false, precioVenta=0.0, remunerativo=true, fechaAlta=Tue Oct 02 16:35:17 ART 2012, ultimaCompra=null, iva=0.0, marca=MARCA..., rubro=Un Rubro, subrubro=null, idunidadmedida=UNITARIO}}]})
	at org.eclipse.persistence.internal.jpa.transaction.EntityTransactionImpl.commitInternal(EntityTransactionImpl.java:102)
	at org.eclipse.persistence.internal.jpa.transaction.EntityTransactionImpl.commit(EntityTransactionImpl.java:63)
	at jpa.controller.AbstractDAO.create(AbstractDAO.java:45)



SOLVED: REMOVED @Basic annotation, but i dont know why it worked

[Updated on: Fri, 12 October 2012 13:44]

Report message to a moderator

Re: misunderstanding annotations [message #941395 is a reply to message #941221] Fri, 12 October 2012 13:34 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1039
Registered: July 2009
Senior Member
Hello,

You have the @Basic annotation as well as the @ManyToOne annotation on usuario and proveedor. They can't be both a basic (which is serialized, hence the byte array expectation) and a relationship using a join column at the same time.

Try removing the @Basic.

Best Regards,
Chris
Re: misunderstanding annotations [message #941408 is a reply to message #941395] Fri, 12 October 2012 13:45 Go to previous message
FiruzzZ Mising name is currently offline FiruzzZ Mising nameFriend
Messages: 19
Registered: October 2011
Junior Member
thanks for the explanation
Previous Topic:Annotation @Lob - Trying to save files on Oracle DB
Next Topic:ArrayIndexOutOfBounds during commit
Goto Forum:
  


Current Time: Mon Dec 22 07:10:29 GMT 2014

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

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