Discussion:
[Middlegen-user] mysql autoincrement pk
José Manuel Molina Pascual
2004-01-22 09:24:34 UTC
Permalink
Timothy Peter Cockle
2004-01-22 10:06:03 UTC
Permalink
Sounds odd as the create should return the entity bean.
Attach the relevant code and build file.

Tim
Hy,
I'm used middlegen to generate code from a database schema, I has
InnoDB tables into a mysql database,
In particular, I have one table with an autoincrement pk field (well,
in fact, all the tables have an autoincrement pk field), wich is
causing me some problems.
This table, has a child table (1 - 0..N Relation) well, thay work
fairly well if you create first one row int he parent table, then you
manage to get its local instance (I call them from a session bean, so
I use the local interfaces), and then insert the childs wioth this
local object in the create call.
The problem arises as, from the client app, the user can create a new
structure (a new parent with new childs) and then I need to create the
parent (this step its ok) an then get this newly created parent and
insert the childs, this second step is what is causing me problems.
First, the aprent create method returns me null, The bean returns a
PKFactura (the table is called Factura) but the method in the
localhome interface (generated with XDoclet using the tgas generated
with middlegen) returns a FacturaLocalHome object, I thinks its ok as
Jbosss deploys it ok and I don't know what the specification says
about this, anyway, as I said the create method returns null, nor the
PK nor the newly created entity.
So, here arises the problem, I have no way to get this entity without
user intervention, as no other field is unique, I dont know the pk the
mysql engine asigned the new parent row.
The only way i think I have to get the pk it with the SELECT
LAST_INSERTED_ID() SQL sentence, I havent tested yet but I'm not sure
* It returns the last inserted autoincrement value on a
connection base, so if Jboss doesn't employ the same
connection to insert the parents and the childs, i wont do, or
if the same connection is used by jboss to insert one parent,
then another parent , then the childs from the first
parent......... it won't do.
In fact I'm not sure about the behaviour of jboss at this point, th
parent and the childs, are inserted in the same method of the wrapper
session bean, maybe, its done into one transaction, and so inside the
same connection.
Well, does anyone knows if the LAST_INSERTED_ID() aproach will
do????????
--
José Manuel Molina Pascual
Stratesys Consulting
C/ Juan de Mena, 6
Madrid 28014
Tel (+34) 91 360 49 60
José Manuel Molina Pascual
2004-02-22 20:01:05 UTC
Permalink
Ok, here it goes, I paste the relevant code and and attach the files and
its xdoclet build file.

Here's the exception I get, well, actually, I debugged the jboss
execution and the FacturaLocal object is not null but is not the entity
just created.

It seems to me that it passes the if condition !!!!!! but somehow its
not usefull

org.jboss.tm.JBossTransactionRolledbackException: Attempt to get lock
ref with a null object; CausedByException is:
Attempt to get lock ref with a null object; nested exception is:
java.lang.IllegalArgumentException: Attempt to get lock ref with a
null object; - nested throwable: (java.lang.IllegalArgumentException:
Attempt to get lock ref with a null object)
at
org.jboss.ejb.plugins.LogInterceptor.handleException(LogInterceptor.java:262)
at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:195)
at
org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
at
org.jboss.ejb.StatelessSessionContainer.internalInvoke(StatelessSessionContainer.java:322)
at org.jboss.ejb.Container.invoke(Container.java:674)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at
org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:549)
at
org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:359)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
at sun.rmi.transport.Transport$1.run(Transport.java:148)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
at
sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
at
sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
at java.lang.Thread.run(Thread.java:534)
Caused by: java.lang.IllegalArgumentException: Attempt to get lock ref
with a null object
at org.jboss.ejb.BeanLockManager.getLock(BeanLockManager.java:80)
at
org.jboss.ejb.plugins.EntityLockInterceptor.invoke(EntityLockInterceptor.java:81)
at
org.jboss.ejb.plugins.EntityCreationInterceptor.invoke(EntityCreationInterceptor.java:53)
at
org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:84)
at
org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:243)
at
org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:104)
at
org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:117)
at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:191)
at
org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
at
org.jboss.ejb.EntityContainer.internalInvoke(EntityContainer.java:483)
at org.jboss.ejb.Container.invoke(Container.java:674)
at
org.jboss.ejb.plugins.local.BaseLocalProxyFactory.invoke(BaseLocalProxyFactory.java:353)
at org.jboss.ejb.plugins.local.EntityProxy.invoke(EntityProxy.java:38)
at $Proxy84.getPkfactura(Unknown Source)
at
gcc.fac.wrp.FacturacionWrapperBean.insertarFactura(FacturacionWrapperBean.java:173)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at
org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:629)
at
org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:186)
at
org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:72)
at
org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:84)
at
org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:243)
at
org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:104)
at
org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:117)
at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:191)
... 21 more



####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################





Relevant code in FacturacionWrapperBean, the method
/**
* @param factura
* @return
* @throws NamingException
* @throws RemoteException
* @throws CreateException
* @throws FinderException
* @ejb.interface-method view-type = "remote"
*/
public Boolean insertarFactura( gcc.fac.jdo.Factura factura) throws
NamingException, RemoteException, CreateException,FinderException {
Boolean resultado = null;
FacturaLocal facturaLocal;
FacturaLocalHome facturaLocalHome;
ConceptoLocal conceptoLocal;
ConceptoLocalHome conceptoLocalHome;
Concepto[] conceptos;


facturaLocalHome = FacturaUtil.getLocalHome();
conceptoLocalHome = ConceptoUtil.getLocalHome();
Calendar fechaCal;
if (factura.getFecha() != null){
fechaCal = factura.getFecha();
}else{
fechaCal = Calendar.getInstance();
}
Date fecha = new Date(fechaCal.getTimeInMillis());



byte pagada = Util.boolean2Byte(factura.getPagada().booleanValue());
byte albaran =
Util.boolean2Byte(factura.getAlbaran().booleanValue());
Long b = new Long(1);

facturaLocal =
facturaLocalHome.create(factura.getNombreCliente(),factura.getDirCliente(),factura.getObservaciones(),pagada,factura.getTipoPago(),null

,factura.getCodigoFactura(),factura.getPKPaciente().longValue(),fecha,factura.getDNICliente()

,factura.getCPCliente().intValue(),factura.getCiudadCliente(),factura.getProvinciaCliente(),factura.getPaisCliente(),albaran,0);

//facturaLocal = (FacturaLocal)
facturaLocalHome.findByCodigoFactura(factura.getCodigoFactura()).iterator().next();
System.out.println("insert parent passed");
if(facturaLocal.getPkfactura()!= null){ //I dont know how it
manages to pass this condition, anyway, it does not print nothing in the
server output.
System.out.println(facturaLocal.getPkfactura().toString());
conceptos = factura.getConceptos();
if (conceptos != null){
for (int i=0; i< conceptos.length; i++){

conceptoLocalHome.create(conceptos[i].getDescripcion(),conceptos[i].getPrecio().doubleValue(),
conceptos[i].getPctImpuestos().doubleValue(),null,0,
conceptos[i].getCantidad().intValue(),facturaLocal);
}
}
}

return resultado;
}


####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################




The create methods in ConceptoBean

/**
* This create method takes only mandatory (non-nullable) parameters.
*
* When the client invokes a create method, the EJB container invokes
the ejbCreate method.
* Typically, an ejbCreate method in an entity bean performs the
following tasks:
* <UL>
* <LI>Inserts the entity state into the database.</LI>
* <LI>Initializes the instance variables.</LI>
* <LI>Returns the primary key.</LI>
* </UL>
*
* @param concepto the concepto value
* @param valor the valor value
* @param impuestos the impuestos value
* @param pkconcepto the pkconcepto value
* @param cantidad the cantidad value
* @param factura mandatory CMR field
* @return the primary key of the new instance
*
* @ejb.create-method
*/
public gcc.fac.ejb.ConceptoPK ejbCreate( java.lang.String concepto,
double valor, double impuestos, java.lang.Long pkconcepto, int cantidad,
gcc.fac.ejb.FacturaLocal factura ) throws javax.ejb.CreateException {
// Set CMP fields
setConcepto(concepto);
setValor(valor);
setImpuestos(impuestos);
setPkconcepto(pkconcepto);
setCantidad(cantidad);
setPkfactura(factura.getPkfactura());
// EJB 2.0 spec says return null for CMP ejbCreate methods.
return null;
}

/**
* The container invokes thos method immediately after it calls
ejbCreate.
*
* @param concepto the concepto value
* @param valor the valor value
* @param impuestos the impuestos value
* @param pkconcepto the pkconcepto value
* @param cantidad the cantidad value
* @param factura mandatory CMR field
*/
public void ejbPostCreate( java.lang.String concepto, double valor,
double impuestos, java.lang.Long pkconcepto, int cantidad,
gcc.fac.ejb.FacturaLocal factura ) throws javax.ejb.CreateException {
// Set CMR fields
setFactura(factura);
}

/**
* This create method takes all parameters (both nullable and not
nullable).
*
* When the client invokes a create method, the EJB container invokes
the ejbCreate method.
* Typically, an ejbCreate method in an entity bean performs the
following tasks:
* <UL>
* <LI>Inserts the entity state into the database.</LI>
* <LI>Initializes the instance variables.</LI>
* <LI>Returns the primary key.</LI>
* </UL>
*
* @param concepto the concepto value
* @param valor the valor value
* @param impuestos the impuestos value
* @param pkconcepto the pkconcepto value
* @param pkintervencion the pkintervencion value
* @param cantidad the cantidad value
* @param factura CMR field
* @return the primary key of the new instance
*
* @ejb.create-method
*/
public gcc.fac.ejb.ConceptoPK ejbCreate( java.lang.String concepto,
double valor, double impuestos, java.lang.Long pkconcepto, long
pkintervencion, int cantidad, gcc.fac.ejb.FacturaLocal factura ) throws
javax.ejb.CreateException {
// Set CMP fields
setConcepto(concepto);
setValor(valor);
setImpuestos(impuestos);
setPkconcepto(pkconcepto);
setPkintervencion(pkintervencion);
setCantidad(cantidad);
setPkfactura(factura.getPkfactura());
// EJB 2.0 spec says return null for CMP ejbCreate methods.
return null;
}


####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################



The create methods on FacturaBean

/**
* This create method takes only mandatory (non-nullable) parameters.
*
* When the client invokes a create method, the EJB container invokes
the ejbCreate method.
* Typically, an ejbCreate method in an entity bean performs the
following tasks:
* <UL>
* <LI>Inserts the entity state into the database.</LI>
* <LI>Initializes the instance variables.</LI>
* <LI>Returns the primary key.</LI>
* </UL>
*
* @param observaciones the observaciones value
* @param pagada the pagada value
* @param tipoPago the tipoPago value
* @param pkfactura the pkfactura value
* @param fecha the fecha value
* @return the primary key of the new instance
*
* @ejb.create-method
*/
public gcc.fac.ejb.FacturaPK ejbCreate( java.lang.Object
observaciones, byte pagada, java.lang.String tipoPago, java.lang.Long
pkfactura, java.sql.Date fecha ) throws javax.ejb.CreateException {
// Set CMP fields
setObservaciones(observaciones);
setPagada(pagada);
setTipoPago(tipoPago);
setPkfactura(pkfactura);
setFecha(fecha);
// EJB 2.0 spec says return null for CMP ejbCreate methods.
return null;
}

/**
* The container invokes thos method immediately after it calls
ejbCreate.
*
* @param observaciones the observaciones value
* @param pagada the pagada value
* @param tipoPago the tipoPago value
* @param pkfactura the pkfactura value
* @param fecha the fecha value
*/
public void ejbPostCreate( java.lang.Object observaciones, byte
pagada, java.lang.String tipoPago, java.lang.Long pkfactura,
java.sql.Date fecha ) throws javax.ejb.CreateException {
// Set CMR fields
}

/**
* This create method takes all parameters (both nullable and not
nullable).
*
* When the client invokes a create method, the EJB container invokes
the ejbCreate method.
* Typically, an ejbCreate method in an entity bean performs the
following tasks:
* <UL>
* <LI>Inserts the entity state into the database.</LI>
* <LI>Initializes the instance variables.</LI>
* <LI>Returns the primary key.</LI>
* </UL>
*
* @param nombreCliente the nombreCliente value
* @param dirCliente the dirCliente value
* @param observaciones the observaciones value
* @param pagada the pagada value
* @param tipoPago the tipoPago value
* @param pkfactura the pkfactura value
* @param codigoFactura the codigoFactura value
* @param pkpaciente the pkpaciente value
* @param fecha the fecha value
* @param dnicliente the dnicliente value
* @param cpcliente the cpcliente value
* @param ciudadCliente the ciudadCliente value
* @param provinciaCliente the provinciaCliente value
* @param paisCliente the paisCliente value
* @param albaran the albaran value
* @param pkcita the pkcita value
* @return the primary key of the new instance
*
* @ejb.create-method
*/
public gcc.fac.ejb.FacturaPK ejbCreate( java.lang.String
nombreCliente, java.lang.String dirCliente, java.lang.Object
observaciones, byte pagada, java.lang.String tipoPago, java.lang.Long
pkfactura, java.lang.String codigoFactura, long pkpaciente,
java.sql.Date fecha, java.lang.String dnicliente, int cpcliente,
java.lang.String ciudadCliente, java.lang.String provinciaCliente,
java.lang.String paisCliente, byte albaran, long pkcita ) throws
javax.ejb.CreateException {
// Set CMP fields
setNombreCliente(nombreCliente);
setDirCliente(dirCliente);
setObservaciones(observaciones);
setPagada(pagada);
setTipoPago(tipoPago);
setPkfactura(pkfactura);
setCodigoFactura(codigoFactura);
setPkpaciente(pkpaciente);
setFecha(fecha);
setDnicliente(dnicliente);
setCpcliente(cpcliente);
setCiudadCliente(ciudadCliente);
setProvinciaCliente(provinciaCliente);
setPaisCliente(paisCliente);
setAlbaran(albaran);
setPkcita(pkcita);
// EJB 2.0 spec says return null for CMP ejbCreate methods.
return null;
}

/**
* The container invokes thos method immediately after it calls
ejbCreate.
*
* @param nombreCliente the nombreCliente value
* @param dirCliente the dirCliente value
* @param observaciones the observaciones value
* @param pagada the pagada value
* @param tipoPago the tipoPago value
* @param pkfactura the pkfactura value
* @param codigoFactura the codigoFactura value
* @param pkpaciente the pkpaciente value
* @param fecha the fecha value
* @param dnicliente the dnicliente value
* @param cpcliente the cpcliente value
* @param ciudadCliente the ciudadCliente value
* @param provinciaCliente the provinciaCliente value
* @param paisCliente the paisCliente value
* @param albaran the albaran value
* @param pkcita the pkcita value
*/
public void ejbPostCreate( java.lang.String nombreCliente,
java.lang.String dirCliente, java.lang.Object observaciones, byte
pagada, java.lang.String tipoPago, java.lang.Long pkfactura,
java.lang.String codigoFactura, long pkpaciente, java.sql.Date fecha,
java.lang.String dnicliente, int cpcliente, java.lang.String
ciudadCliente, java.lang.String provinciaCliente, java.lang.String
paisCliente, byte albaran, long pkcita ) throws javax.ejb.CreateException {
// Set CMR fields
}
Post by Timothy Peter Cockle
Sounds odd as the create should return the entity bean.
Attach the relevant code and build file.
Tim
Hy,
I'm used middlegen to generate code from a database schema, I has
InnoDB tables into a mysql database,
In particular, I have one table with an autoincrement pk field (well,
in fact, all the tables have an autoincrement pk field), wich is
causing me some problems.
This table, has a child table (1 - 0..N Relation) well, thay work
fairly well if you create first one row int he parent table, then you
manage to get its local instance (I call them from a session bean, so
I use the local interfaces), and then insert the childs wioth this
local object in the create call.
The problem arises as, from the client app, the user can create a new
structure (a new parent with new childs) and then I need to create the
parent (this step its ok) an then get this newly created parent and
insert the childs, this second step is what is causing me problems.
First, the aprent create method returns me null, The bean returns a
PKFactura (the table is called Factura) but the method in the
localhome interface (generated with XDoclet using the tgas generated
with middlegen) returns a FacturaLocalHome object, I thinks its ok as
Jbosss deploys it ok and I don't know what the specification says
about this, anyway, as I said the create method returns null, nor the
PK nor the newly created entity.
So, here arises the problem, I have no way to get this entity without
user intervention, as no other field is unique, I dont know the pk the
mysql engine asigned the new parent row.
The only way i think I have to get the pk it with the SELECT
LAST_INSERTED_ID() SQL sentence, I havent tested yet but I'm not sure
* It returns the last inserted autoincrement value on a
connection base, so if Jboss doesn't employ the same
connection to insert the parents and the childs, i wont do, or
if the same connection is used by jboss to insert one parent,
then another parent , then the childs from the first
parent......... it won't do.
In fact I'm not sure about the behaviour of jboss at this point, th
parent and the childs, are inserted in the same method of the wrapper
session bean, maybe, its done into one transaction, and so inside the
same connection.
Well, does anyone knows if the LAST_INSERTED_ID() aproach will
do????????
--
José Manuel Molina Pascual
Stratesys Consulting
C/ Juan de Mena, 6
Madrid 28014
Tel (+34) 91 360 49 60
-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
_______________________________________________
middlegen-user mailing list
https://lists.sourceforge.net/lists/listinfo/middlegen-user
--
José Manuel Molina Pascual
***@stratesys.es <mailto:***@stratesys.es>
/*
Stratesys Consulting */
C/ Juan de Mena, 6
Madrid 28014
Tel (+34) 91 360 49 60
José Manuel Molina Pascual
2004-02-22 20:01:07 UTC
Permalink
Ok, here it goes, I paste the relevant code and and attach the files and
its xdoclet build file.

Here's the exception I get, well, actually, I debugged the jboss
execution and the FacturaLocal object is not null but is not the entity
just created.

It seems to me that it passes the if condition !!!!!! but somehow its
not usefull

org.jboss.tm.JBossTransactionRolledbackException: Attempt to get lock
ref with a null object; CausedByException is:
Attempt to get lock ref with a null object; nested exception is:
java.lang.IllegalArgumentException: Attempt to get lock ref with a
null object; - nested throwable: (java.lang.IllegalArgumentException:
Attempt to get lock ref with a null object)
at
org.jboss.ejb.plugins.LogInterceptor.handleException(LogInterceptor.java:262)
at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:195)
at
org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
at
org.jboss.ejb.StatelessSessionContainer.internalInvoke(StatelessSessionContainer.java:322)
at org.jboss.ejb.Container.invoke(Container.java:674)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at
org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:549)
at
org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:359)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
at sun.rmi.transport.Transport$1.run(Transport.java:148)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
at
sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
at
sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
at java.lang.Thread.run(Thread.java:534)
Caused by: java.lang.IllegalArgumentException: Attempt to get lock ref
with a null object
at org.jboss.ejb.BeanLockManager.getLock(BeanLockManager.java:80)
at
org.jboss.ejb.plugins.EntityLockInterceptor.invoke(EntityLockInterceptor.java:81)
at
org.jboss.ejb.plugins.EntityCreationInterceptor.invoke(EntityCreationInterceptor.java:53)
at
org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:84)
at
org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:243)
at
org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:104)
at
org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:117)
at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:191)
at
org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
at
org.jboss.ejb.EntityContainer.internalInvoke(EntityContainer.java:483)
at org.jboss.ejb.Container.invoke(Container.java:674)
at
org.jboss.ejb.plugins.local.BaseLocalProxyFactory.invoke(BaseLocalProxyFactory.java:353)
at org.jboss.ejb.plugins.local.EntityProxy.invoke(EntityProxy.java:38)
at $Proxy84.getPkfactura(Unknown Source)
at
gcc.fac.wrp.FacturacionWrapperBean.insertarFactura(FacturacionWrapperBean.java:173)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at
org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:629)
at
org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:186)
at
org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:72)
at
org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:84)
at
org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:243)
at
org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:104)
at
org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:117)
at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:191)
... 21 more



####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################





Relevant code in FacturacionWrapperBean, the method
/**
* @param factura
* @return
* @throws NamingException
* @throws RemoteException
* @throws CreateException
* @throws FinderException
* @ejb.interface-method view-type = "remote"
*/
public Boolean insertarFactura( gcc.fac.jdo.Factura factura) throws
NamingException, RemoteException, CreateException,FinderException {
Boolean resultado = null;
FacturaLocal facturaLocal;
FacturaLocalHome facturaLocalHome;
ConceptoLocal conceptoLocal;
ConceptoLocalHome conceptoLocalHome;
Concepto[] conceptos;


facturaLocalHome = FacturaUtil.getLocalHome();
conceptoLocalHome = ConceptoUtil.getLocalHome();
Calendar fechaCal;
if (factura.getFecha() != null){
fechaCal = factura.getFecha();
}else{
fechaCal = Calendar.getInstance();
}
Date fecha = new Date(fechaCal.getTimeInMillis());



byte pagada =
Util.boolean2Byte(factura.getPagada().booleanValue());
byte albaran =
Util.boolean2Byte(factura.getAlbaran().booleanValue());
Long b = new Long(1);

facturaLocal =
facturaLocalHome.create(factura.getNombreCliente(),factura.getDirCliente(),factura.getObservaciones(),pagada,factura.getTipoPago(),null

,factura.getCodigoFactura(),factura.getPKPaciente().longValue(),fecha,factura.getDNICliente()

,factura.getCPCliente().intValue(),factura.getCiudadCliente(),factura.getProvinciaCliente(),factura.getPaisCliente(),albaran,0);

System.out.println("insert parent passed");
if(facturaLocal.getPkfactura()!= null){ // Here, its where the
exception is throw, it tries to get the pk and fails, as it seems to me,
facturaLocal is not the representation of the newly inserted parent.


System.out.println(facturaLocal.getPkfactura().toString());
conceptos = factura.getConceptos();
if (conceptos != null){
for (int i=0; i< conceptos.length; i++){

conceptoLocalHome.create(conceptos[i].getDescripcion(),conceptos[i].getPrecio().doubleValue(),
conceptos[i].getPctImpuestos().doubleValue(),null,0,
conceptos[i].getCantidad().intValue(),facturaLocal);
}
}
}

return resultado;
}


####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################




The create methods in ConceptoBean

/**
* This create method takes only mandatory (non-nullable) parameters.
*
* When the client invokes a create method, the EJB container invokes
the ejbCreate method.
* Typically, an ejbCreate method in an entity bean performs the
following tasks:
* <UL>
* <LI>Inserts the entity state into the database.</LI>
* <LI>Initializes the instance variables.</LI>
* <LI>Returns the primary key.</LI>
* </UL>
*
* @param concepto the concepto value
* @param valor the valor value
* @param impuestos the impuestos value
* @param pkconcepto the pkconcepto value
* @param cantidad the cantidad value
* @param factura mandatory CMR field
* @return the primary key of the new instance
*
* @ejb.create-method
*/
public gcc.fac.ejb.ConceptoPK ejbCreate( java.lang.String concepto,
double valor, double impuestos, java.lang.Long pkconcepto, int cantidad,
gcc.fac.ejb.FacturaLocal factura ) throws javax.ejb.CreateException {
// Set CMP fields
setConcepto(concepto);
setValor(valor);
setImpuestos(impuestos);
setPkconcepto(pkconcepto);
setCantidad(cantidad);
setPkfactura(factura.getPkfactura());
// EJB 2.0 spec says return null for CMP ejbCreate methods.
return null;
}

/**
* The container invokes thos method immediately after it calls
ejbCreate.
*
* @param concepto the concepto value
* @param valor the valor value
* @param impuestos the impuestos value
* @param pkconcepto the pkconcepto value
* @param cantidad the cantidad value
* @param factura mandatory CMR field
*/
public void ejbPostCreate( java.lang.String concepto, double valor,
double impuestos, java.lang.Long pkconcepto, int cantidad,
gcc.fac.ejb.FacturaLocal factura ) throws javax.ejb.CreateException {
// Set CMR fields
setFactura(factura);
}

/**
* This create method takes all parameters (both nullable and not
nullable).
*
* When the client invokes a create method, the EJB container invokes
the ejbCreate method.
* Typically, an ejbCreate method in an entity bean performs the
following tasks:
* <UL>
* <LI>Inserts the entity state into the database.</LI>
* <LI>Initializes the instance variables.</LI>
* <LI>Returns the primary key.</LI>
* </UL>
*
* @param concepto the concepto value
* @param valor the valor value
* @param impuestos the impuestos value
* @param pkconcepto the pkconcepto value
* @param pkintervencion the pkintervencion value
* @param cantidad the cantidad value
* @param factura CMR field
* @return the primary key of the new instance
*
* @ejb.create-method
*/
public gcc.fac.ejb.ConceptoPK ejbCreate( java.lang.String concepto,
double valor, double impuestos, java.lang.Long pkconcepto, long
pkintervencion, int cantidad, gcc.fac.ejb.FacturaLocal factura ) throws
javax.ejb.CreateException {
// Set CMP fields
setConcepto(concepto);
setValor(valor);
setImpuestos(impuestos);
setPkconcepto(pkconcepto);
setPkintervencion(pkintervencion);
setCantidad(cantidad);
setPkfactura(factura.getPkfactura());
// EJB 2.0 spec says return null for CMP ejbCreate methods.
return null;
}


####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################



The create methods on FacturaBean

/**
* This create method takes only mandatory (non-nullable) parameters.
*
* When the client invokes a create method, the EJB container invokes
the ejbCreate method.
* Typically, an ejbCreate method in an entity bean performs the
following tasks:
* <UL>
* <LI>Inserts the entity state into the database.</LI>
* <LI>Initializes the instance variables.</LI>
* <LI>Returns the primary key.</LI>
* </UL>
*
* @param observaciones the observaciones value
* @param pagada the pagada value
* @param tipoPago the tipoPago value
* @param pkfactura the pkfactura value
* @param fecha the fecha value
* @return the primary key of the new instance
*
* @ejb.create-method
*/
public gcc.fac.ejb.FacturaPK ejbCreate( java.lang.Object
observaciones, byte pagada, java.lang.String tipoPago, java.lang.Long
pkfactura, java.sql.Date fecha ) throws javax.ejb.CreateException {
// Set CMP fields
setObservaciones(observaciones);
setPagada(pagada);
setTipoPago(tipoPago);
setPkfactura(pkfactura);
setFecha(fecha);
// EJB 2.0 spec says return null for CMP ejbCreate methods.
return null;
}

/**
* The container invokes thos method immediately after it calls
ejbCreate.
*
* @param observaciones the observaciones value
* @param pagada the pagada value
* @param tipoPago the tipoPago value
* @param pkfactura the pkfactura value
* @param fecha the fecha value
*/
public void ejbPostCreate( java.lang.Object observaciones, byte
pagada, java.lang.String tipoPago, java.lang.Long pkfactura,
java.sql.Date fecha ) throws javax.ejb.CreateException {
// Set CMR fields
}

/**
* This create method takes all parameters (both nullable and not
nullable).
*
* When the client invokes a create method, the EJB container invokes
the ejbCreate method.
* Typically, an ejbCreate method in an entity bean performs the
following tasks:
* <UL>
* <LI>Inserts the entity state into the database.</LI>
* <LI>Initializes the instance variables.</LI>
* <LI>Returns the primary key.</LI>
* </UL>
*
* @param nombreCliente the nombreCliente value
* @param dirCliente the dirCliente value
* @param observaciones the observaciones value
* @param pagada the pagada value
* @param tipoPago the tipoPago value
* @param pkfactura the pkfactura value
* @param codigoFactura the codigoFactura value
* @param pkpaciente the pkpaciente value
* @param fecha the fecha value
* @param dnicliente the dnicliente value
* @param cpcliente the cpcliente value
* @param ciudadCliente the ciudadCliente value
* @param provinciaCliente the provinciaCliente value
* @param paisCliente the paisCliente value
* @param albaran the albaran value
* @param pkcita the pkcita value
* @return the primary key of the new instance
*
* @ejb.create-method
*/
public gcc.fac.ejb.FacturaPK ejbCreate( java.lang.String
nombreCliente, java.lang.String dirCliente, java.lang.Object
observaciones, byte pagada, java.lang.String tipoPago, java.lang.Long
pkfactura, java.lang.String codigoFactura, long pkpaciente,
java.sql.Date fecha, java.lang.String dnicliente, int cpcliente,
java.lang.String ciudadCliente, java.lang.String provinciaCliente,
java.lang.String paisCliente, byte albaran, long pkcita ) throws
javax.ejb.CreateException {
// Set CMP fields
setNombreCliente(nombreCliente);
setDirCliente(dirCliente);
setObservaciones(observaciones);
setPagada(pagada);
setTipoPago(tipoPago);
setPkfactura(pkfactura);
setCodigoFactura(codigoFactura);
setPkpaciente(pkpaciente);
setFecha(fecha);
setDnicliente(dnicliente);
setCpcliente(cpcliente);
setCiudadCliente(ciudadCliente);
setProvinciaCliente(provinciaCliente);
setPaisCliente(paisCliente);
setAlbaran(albaran);
setPkcita(pkcita);
// EJB 2.0 spec says return null for CMP ejbCreate methods.
return null;
}

/**
* The container invokes thos method immediately after it calls
ejbCreate.
*
* @param nombreCliente the nombreCliente value
* @param dirCliente the dirCliente value
* @param observaciones the observaciones value
* @param pagada the pagada value
* @param tipoPago the tipoPago value
* @param pkfactura the pkfactura value
* @param codigoFactura the codigoFactura value
* @param pkpaciente the pkpaciente value
* @param fecha the fecha value
* @param dnicliente the dnicliente value
* @param cpcliente the cpcliente value
* @param ciudadCliente the ciudadCliente value
* @param provinciaCliente the provinciaCliente value
* @param paisCliente the paisCliente value
* @param albaran the albaran value
* @param pkcita the pkcita value
*/
public void ejbPostCreate( java.lang.String nombreCliente,
java.lang.String dirCliente, java.lang.Object observaciones, byte
pagada, java.lang.String tipoPago, java.lang.Long pkfactura,
java.lang.String codigoFactura, long pkpaciente, java.sql.Date fecha,
java.lang.String dnicliente, int cpcliente, java.lang.String
ciudadCliente, java.lang.String provinciaCliente, java.lang.String
paisCliente, byte albaran, long pkcita ) throws javax.ejb.CreateException {
// Set CMR fields
}
Post by Timothy Peter Cockle
Sounds odd as the create should return the entity bean.
Attach the relevant code and build file.
Tim
Hy,
I'm used middlegen to generate code from a database schema, I has
InnoDB tables into a mysql database,
In particular, I have one table with an autoincrement pk field (well,
in fact, all the tables have an autoincrement pk field), wich is
causing me some problems.
This table, has a child table (1 - 0..N Relation) well, thay work
fairly well if you create first one row int he parent table, then you
manage to get its local instance (I call them from a session bean, so
I use the local interfaces), and then insert the childs wioth this
local object in the create call.
The problem arises as, from the client app, the user can create a new
structure (a new parent with new childs) and then I need to create the
parent (this step its ok) an then get this newly created parent and
insert the childs, this second step is what is causing me problems.
First, the aprent create method returns me null, The bean returns a
PKFactura (the table is called Factura) but the method in the
localhome interface (generated with XDoclet using the tgas generated
with middlegen) returns a FacturaLocalHome object, I thinks its ok as
Jbosss deploys it ok and I don't know what the specification says
about this, anyway, as I said the create method returns null, nor the
PK nor the newly created entity.
So, here arises the problem, I have no way to get this entity without
user intervention, as no other field is unique, I dont know the pk the
mysql engine asigned the new parent row.
The only way i think I have to get the pk it with the SELECT
LAST_INSERTED_ID() SQL sentence, I havent tested yet but I'm not sure
* It returns the last inserted autoincrement value on a
connection base, so if Jboss doesn't employ the same
connection to insert the parents and the childs, i wont do, or
if the same connection is used by jboss to insert one parent,
then another parent , then the childs from the first
parent......... it won't do.
In fact I'm not sure about the behaviour of jboss at this point, th
parent and the childs, are inserted in the same method of the wrapper
session bean, maybe, its done into one transaction, and so inside the
same connection.
Well, does anyone knows if the LAST_INSERTED_ID() aproach will
do????????
--
José Manuel Molina Pascual
Stratesys Consulting
C/ Juan de Mena, 6
Madrid 28014
Tel (+34) 91 360 49 60
-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
_______________________________________________
middlegen-user mailing list
https://lists.sourceforge.net/lists/listinfo/middlegen-user
--
José Manuel Molina Pascual
***@stratesys.es <mailto:***@stratesys.es>
/*
Stratesys Consulting */
C/ Juan de Mena, 6
Madrid 28014
Tel (+34) 91 360 49 60
Loading...