Foros del Web » Programación para mayores de 30 ;) » Java »

Ejb-cmp

Estas en el tema de Ejb-cmp en el foro de Java en Foros del Web. La consulta es simple, la solución no lo sé. Como setear los descriptores para hacer que un EJB Entity CMP utilice claves autogeneradas. Uso JBoss ...
  #1 (permalink)  
Antiguo 18/09/2006, 08:23
Avatar de pyanqn  
Fecha de Ingreso: noviembre-2005
Mensajes: 331
Antigüedad: 18 años, 5 meses
Puntos: 8
Ejb-cmp

La consulta es simple, la solución no lo sé.

Como setear los descriptores para hacer que un EJB Entity CMP utilice claves autogeneradas. Uso JBoss 4.0.4 GA.

Gracias
  #2 (permalink)  
Antiguo 18/09/2006, 13:39
 
Fecha de Ingreso: marzo-2006
Mensajes: 54
Antigüedad: 18 años, 1 mes
Puntos: 0
con q version de EJB estas trabajando ??

para las versiones 2.x
es en el descriptor "jbosscmp-jdbc.xml", ahi te vas a encontrar, entre muuuuchas otras cosa, para cada entity todos sus campos, sus opciones por campo, el nombre de la tabla, etc.
solo tienes q agregarle "<auto-increment/>" dentro de los tags "</cmp-field>" al campo q quieres q sea autogenerado.

un ejemplo, un entity que tenga un solo atributo id que es Long y autogenerado se veria en el descriptor "jbosscmp-jdbc.xml" asi:
.....
<enterprise-beans>
<entity>
<ejb-name>MyEntity</ejb-name>
<create-table>true</create-table>
<table-name>myentity</table-name>
<cmp-field>
<field-name>id</field-name>
<column-name>id</column-name>
<jdbc-type>BIGINT</jdbc-type>
<sql-type>BIGINT(20)</sql-type>


<!-- aki es donde le dices q es autogenerado -->
<auto-increment/>

</cmp-field>
<entity-command name="mysql-get-generated-keys">
</entity-command>
.......
  #3 (permalink)  
Antiguo 19/09/2006, 05:48
Avatar de pyanqn  
Fecha de Ingreso: noviembre-2005
Mensajes: 331
Antigüedad: 18 años, 5 meses
Puntos: 8
debo tambien de incluir el tag <entity-command name="mysql-get-generated-keys"></entity-command> ya que estoy usando mysql.

Como estoy usando JBuilder 2006, muchas cosas las genero automaticamente, pero estos dos tag a los que te refieres no aparecen, si existe una solapa deniminada jboss en la cual se pueden setear caracteristicas para claves desconocidas, y es alli en donde se puede indicar que es un campo autoincremento, pero no hace exactamente lo mismo que si lo hago manual.

Gracias
  #4 (permalink)  
Antiguo 19/09/2006, 07:51
Avatar de pyanqn  
Fecha de Ingreso: noviembre-2005
Mensajes: 331
Antigüedad: 18 años, 5 meses
Puntos: 8
He realizado lo que me dices pero tengo errores!!!! No puedo hacer un insert.
Te cuento

Tengo un EJB Entity CMP que se llama Cliente, tiene 3 campos:

idCliente: esta es la clave, autonumerica integer. En la base se llama id_cliente

graciaCliente: String con el nombre del cliente. en la base: gracia_cliente

dirCliente: String con la direccion. en la base: dir_cliente

Luego tengo un EJB Session que la juega de Facade y tiene un metodo para crear Clientes. es el siguiente:

public void newCliente(String nombre, String direccion) {
Cliente cli = null;
try {
javax.naming.Context context = new javax.naming.InitialContext();
ClienteHome cliHome = (ClienteHome) context.lookup("Cliente");
cli = cliHome.create(null);
System.out.println("CLIENTE CREADO.");
cli.setGraciaCliente(nombre);
cli.setDirCliente(direccion);
System.out.println("DATOS ASIGNADOS");
}
catch (NamingException ex) {
ex.printStackTrace();
}
catch (ClassCastException ex) {
ex.printStackTrace();
}
catch(CreateException err){
err.printStackTrace();
}
catch (Exception ex) {
ex.printStackTrace();
}

Eso es todo. los descriptores son:
1º jbosscmp-jdbc.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jbosscmp-jdbc PUBLIC "-//JBoss//DTD JBOSSCMP-JDBC 4.0//EN" "http://www.jboss.org/j2ee/dtd/jbosscmp-jdbc_4_0.dtd">

<jbosscmp-jdbc>
<defaults>
<datasource>java:/MySqlDS</datasource>
<datasource-mapping>mySQL</datasource-mapping>
</defaults>
<enterprise-beans>
<entity>
<ejb-name>Cliente</ejb-name>
<datasource>MySqlDS</datasource>
<datasource-mapping>mySQL</datasource-mapping>
<table-name>cliente</table-name>
<cmp-field>
<field-name>idCliente</field-name>
<column-name>id_cliente</column-name>
<auto-increment />
</cmp-field>
<cmp-field>
<field-name>graciaCliente</field-name>
<column-name>gracia_cliente</column-name>
</cmp-field>
<cmp-field>
<field-name>dirCliente</field-name>
<column-name>dir_cliente</column-name>
</cmp-field>
<entity-command name="mysql-get-generated-keys" />
</entity>
</enterprise-beans>
</jbosscmp-jdbc>



2º el descriptor ejb-jar.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">

<ejb-jar>
<display-name>OrdenesDeCompra</display-name>
<enterprise-beans>
<entity>
<ejb-name>Cliente</ejb-name>
<local-home>ordenes_de_compra.ClienteHome</local-home>
<local>ordenes_de_compra.Cliente</local>
<ejb-class>ordenes_de_compra.ClienteBean</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>java.lang.Object</prim-key-class>
<reentrant>False</reentrant>
<cmp-version>2.x</cmp-version>
<abstract-schema-name>Cliente</abstract-schema-name>
<cmp-field>
<field-name>idCliente</field-name>
</cmp-field>
<cmp-field>
<field-name>graciaCliente</field-name>
</cmp-field>
<cmp-field>
<field-name>dirCliente</field-name>
</cmp-field>
</entity>
<session>
<ejb-name>FacadeCliente</ejb-name>
<home>ordenes_de_compra.FacadeClienteHome</home>
<remote>ordenes_de_compra.FacadeCliente</remote>
<ejb-class>ordenes_de_compra.FacadeClienteBean</ejb-class>
<session-type>Stateful</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
<assembly-descriptor>
<container-transaction>
<method>
<ejb-name>Cliente</ejb-name>
<method-name>*</method-name>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>
<container-transaction>
<method>
<ejb-name>FacadeCliente</ejb-name>
<method-name>*</method-name>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>
</assembly-descriptor>
</ejb-jar>

En el mensaje que sigue los errores capturados al intentar crear un nuevo cliente con clave autonumerica.
  #5 (permalink)  
Antiguo 19/09/2006, 08:13
Avatar de pyanqn  
Fecha de Ingreso: noviembre-2005
Mensajes: 331
Antigüedad: 18 años, 5 meses
Puntos: 8
Esto son los errores arrojados por el JBoss, puse mensajes para saber si encontraba el contexto y otros para saber si insertaba pero...

11:07:26,288 INFO [STDOUT] EJB Entity CMP Cliente ENONTRADO...
11:08:05,366 ERROR [Cliente] Could not create entity
java.sql.SQLException: Field 'Cliente_upk' doesn't have a default value
at com.mysql.jdbc.SQLError.createSQLException(SQLErro r.java:946)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.ja va:2822)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:15 36)
at com.mysql.jdbc.ServerPreparedStatement.serverExecu te(ServerPreparedStatement.java:1159)
at com.mysql.jdbc.ServerPreparedStatement.executeInte rnal(ServerPreparedStatement.java:684)
at com.mysql.jdbc.PreparedStatement.executeUpdate(Pre paredStatement.java:1184)
at com.mysql.jdbc.PreparedStatement.executeUpdate(Pre paredStatement.java:1101)
at com.mysql.jdbc.PreparedStatement.executeUpdate(Pre paredStatement.java:1086)
at org.jboss.resource.adapter.jdbc.WrappedPreparedSta tement.executeUpdate(WrappedPreparedStatement.java :251)
at org.jboss.ejb.plugins.cmp.jdbc.keygen.JDBCMySQLCre ateCommand.executeInsert(JDBCMySQLCreateCommand.ja va:107)
at org.jboss.ejb.plugins.cmp.jdbc.JDBCAbstractCreateC ommand.performInsert(JDBCAbstractCreateCommand.jav a:321)
at org.jboss.ejb.plugins.cmp.jdbc.JDBCAbstractCreateC ommand.execute(JDBCAbstractCreateCommand.java:151)
at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.cr eateEntity(JDBCStoreManager.java:587)
at org.jboss.ejb.plugins.CMPPersistenceManager.create Entity(CMPPersistenceManager.java:237)
at org.jboss.resource.connectionmanager.CachedConnect ionInterceptor.createEntity(CachedConnectionInterc eptor.java:225)
at org.jboss.ejb.EntityContainer.createLocalHome(Enti tyContainer.java:618)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.invocation.Invocation.performCall(Invoca tion.java:359)
at org.jboss.ejb.EntityContainer$ContainerInterceptor .invokeHome(EntityContainer.java:1130)
at org.jboss.ejb.plugins.AbstractInterceptor.invokeHo me(AbstractInterceptor.java:105)
at org.jboss.ejb.plugins.EntitySynchronizationInterce ptor.invokeHome(EntitySynchronizationInterceptor.j ava:203)
at org.jboss.resource.connectionmanager.CachedConnect ionInterceptor.invokeHome(CachedConnectionIntercep tor.java:189)
at org.jboss.ejb.plugins.AbstractInterceptor.invokeHo me(AbstractInterceptor.java:105)
at org.jboss.ejb.plugins.EntityInstanceInterceptor.in vokeHome(EntityInstanceInterceptor.java:134)
at org.jboss.ejb.plugins.EntityLockInterceptor.invoke Home(EntityLockInterceptor.java:76)
at org.jboss.ejb.plugins.EntityCreationInterceptor.in vokeHome(EntityCreationInterceptor.java:43)
at org.jboss.ejb.plugins.CallValidationInterceptor.in vokeHome(CallValidationInterceptor.java:56)
at org.jboss.ejb.plugins.AbstractTxInterceptor.invoke Next(AbstractTxInterceptor.java:125)
at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTran sactions(TxInterceptorCMT.java:350)
at org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome( TxInterceptorCMT.java:161)
at org.jboss.ejb.plugins.SecurityInterceptor.invokeHo me(SecurityInterceptor.java:145)
at org.jboss.ejb.plugins.LogInterceptor.invokeHome(Lo gInterceptor.java:132)
at org.jboss.ejb.plugins.ProxyFactoryFinderIntercepto r.invokeHome(ProxyFactoryFinderInterceptor.java:10 7)
at org.jboss.ejb.EntityContainer.internalInvokeHome(E ntityContainer.java:514)
at org.jboss.ejb.Container.invoke(Container.java:975)
at org.jboss.ejb.plugins.local.BaseLocalProxyFactory. invokeHome(BaseLocalProxyFactory.java:359)
at org.jboss.ejb.plugins.local.LocalHomeProxy.invoke( LocalHomeProxy.java:133)
at $Proxy89.create(Unknown Source)
at ordenes_de_compra.FacadeClienteBean.newCliente(Fac adeClienteBean.java:33)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.invocation.Invocation.performCall(Invoca tion.java:359)
at org.jboss.ejb.StatefulSessionContainer$ContainerIn terceptor.invoke(StatefulSessionContainer.java:598 )
at org.jboss.ejb.plugins.SecurityInterceptor.invoke(S ecurityInterceptor.java:168)
at org.jboss.resource.connectionmanager.CachedConnect ionInterceptor.invoke(CachedConnectionInterceptor. java:158)
at org.jboss.ejb.plugins.StatefulSessionInstanceInter ceptor.invoke(StatefulSessionInstanceInterceptor.j ava:330)
at org.jboss.ejb.plugins.CallValidationInterceptor.in voke(CallValidationInterceptor.java:63)
at org.jboss.ejb.plugins.AbstractTxInterceptor.invoke Next(AbstractTxInterceptor.java:121)
at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTran sactions(TxInterceptorCMT.java:350)
at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxIn terceptorCMT.java:181)
at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInt erceptor.java:205)
at org.jboss.ejb.plugins.ProxyFactoryFinderIntercepto r.invoke(ProxyFactoryFinderInterceptor.java:136)
at org.jboss.ejb.SessionContainer.internalInvoke(Sess ionContainer.java:648)
at org.jboss.ejb.Container.invoke(Container.java:954)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.mx.interceptor.ReflectedDispatcher.invok e(ReflectedDispatcher.java:155)
at org.jboss.mx.server.Invocation.dispatch(Invocation .java:94)
at org.jboss.mx.server.Invocation.invoke(Invocation.j ava:86)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(Ab stractMBeanInvoker.java:264)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanSe rverImpl.java:659)
at org.jboss.invocation.jrmp.server.JRMPInvoker$MBean ServerAction.invoke(JRMPInvoker.java:819)
at org.jboss.invocation.jrmp.server.JRMPInvoker.invok e(JRMPInvoker.java:420)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastSe rverRef.java:294)
at sun.rmi.transport.Transport$1.run(Transport.java:1 53)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport. java:149)
at sun.rmi.transport.tcp.TCPTransport.handleMessages( TCPTransport.java:460)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandl er.run(TCPTransport.java:701)
at java.lang.Thread.run(Thread.java:595)
11:08:05,444 ERROR [STDERR] javax.ejb.CreateException: Could not create entity:java.sql.SQLException: Field 'Cliente_upk' doesn't have a default value
11:08:05,444 ERROR [STDERR] at org.jboss.ejb.plugins.cmp.jdbc.JDBCAbstractCreateC ommand.performInsert(JDBCAbstractCreateCommand.jav a:340)
11:08:05,444 ERROR [STDERR] at org.jboss.ejb.plugins.cmp.jdbc.JDBCAbstractCreateC ommand.execute(JDBCAbstractCreateCommand.java:151)
11:08:05,444 ERROR [STDERR] at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.cr eateEntity(JDBCStoreManager.java:587)
11:08:05,444 ERROR [STDERR] at org.jboss.ejb.plugins.CMPPersistenceManager.create Entity(CMPPersistenceManager.java:237)
11:08:05,444 ERROR [STDERR] at org.jboss.resource.connectionmanager.CachedConnect ionInterceptor.createEntity(CachedConnectionInterc eptor.java:225)
11:08:05,444 ERROR [STDERR] at org.jboss.ejb.EntityContainer.createLocalHome(Enti tyContainer.java:618)
11:08:05,444 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
11:08:05,444 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
11:08:05,444 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
11:08:05,444 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
11:08:05,444 ERROR [STDERR] at org.jboss.invocation.Invocation.performCall(Invoca tion.java:359)
11:08:05,444 ERROR [STDERR] at org.jboss.ejb.EntityContainer$ContainerInterceptor .invokeHome(EntityContainer.java:1130)
11:08:05,444 ERROR [STDERR] at org.jboss.ejb.plugins.AbstractInterceptor.invokeHo me(AbstractInterceptor.java:105)
11:08:05,444 ERROR [STDERR] at org.jboss.ejb.plugins.EntitySynchronizationInterce ptor.invokeHome(EntitySynchronizationInterceptor.j ava:203)
11:08:05,444 ERROR [STDERR] at org.jboss.resource.connectionmanager.CachedConnect ionInterceptor.invokeHome(CachedConnectionIntercep tor.java:189)
11:08:05,444 ERROR [STDERR] at org.jboss.ejb.plugins.AbstractInterceptor.invokeHo me(AbstractInterceptor.java:105)
11:08:05,444 ERROR [STDERR] at org.jboss.ejb.plugins.EntityInstanceInterceptor.in vokeHome(EntityInstanceInterceptor.java:134)
11:08:05,444 ERROR [STDERR] at org.jboss.ejb.plugins.EntityLockInterceptor.invoke Home(EntityLockInterceptor.java:76)


y sigue...
  #6 (permalink)  
Antiguo 19/09/2006, 08:13
Avatar de pyanqn  
Fecha de Ingreso: noviembre-2005
Mensajes: 331
Antigüedad: 18 años, 5 meses
Puntos: 8
11:08:05,444 ERROR [STDERR] at org.jboss.ejb.plugins.EntityCreationInterceptor.in vokeHome(EntityCreationInterceptor.java:43)
11:08:05,444 ERROR [STDERR] at org.jboss.ejb.plugins.CallValidationInterceptor.in vokeHome(CallValidationInterceptor.java:56)
11:08:05,444 ERROR [STDERR] at org.jboss.ejb.plugins.AbstractTxInterceptor.invoke Next(AbstractTxInterceptor.java:125)
11:08:05,444 ERROR [STDERR] at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTran sactions(TxInterceptorCMT.java:350)
11:08:05,444 ERROR [STDERR] at org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome( TxInterceptorCMT.java:161)
11:08:05,444 ERROR [STDERR] at org.jboss.ejb.plugins.SecurityInterceptor.invokeHo me(SecurityInterceptor.java:145)
11:08:05,444 ERROR [STDERR] at org.jboss.ejb.plugins.LogInterceptor.invokeHome(Lo gInterceptor.java:132)
11:08:05,444 ERROR [STDERR] at org.jboss.ejb.plugins.ProxyFactoryFinderIntercepto r.invokeHome(ProxyFactoryFinderInterceptor.java:10 7)
11:08:05,444 ERROR [STDERR] at org.jboss.ejb.EntityContainer.internalInvokeHome(E ntityContainer.java:514)
11:08:05,444 ERROR [STDERR] at org.jboss.ejb.Container.invoke(Container.java:975)
11:08:05,444 ERROR [STDERR] at org.jboss.ejb.plugins.local.BaseLocalProxyFactory. invokeHome(BaseLocalProxyFactory.java:359)
11:08:05,444 ERROR [STDERR] at org.jboss.ejb.plugins.local.LocalHomeProxy.invoke( LocalHomeProxy.java:133)
11:08:05,444 ERROR [STDERR] at $Proxy89.create(Unknown Source)
11:08:05,444 ERROR [STDERR] at ordenes_de_compra.FacadeClienteBean.newCliente(Fac adeClienteBean.java:33)
11:08:05,444 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
11:08:05,444 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
11:08:05,444 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
11:08:05,444 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
11:08:05,444 ERROR [STDERR] at org.jboss.invocation.Invocation.performCall(Invoca tion.java:359)
11:08:05,444 ERROR [STDERR] at org.jboss.ejb.StatefulSessionContainer$ContainerIn terceptor.invoke(StatefulSessionContainer.java:598 )
11:08:05,444 ERROR [STDERR] at org.jboss.ejb.plugins.SecurityInterceptor.invoke(S ecurityInterceptor.java:168)
11:08:05,444 ERROR [STDERR] at org.jboss.resource.connectionmanager.CachedConnect ionInterceptor.invoke(CachedConnectionInterceptor. java:158)
11:08:05,444 ERROR [STDERR] at org.jboss.ejb.plugins.StatefulSessionInstanceInter ceptor.invoke(StatefulSessionInstanceInterceptor.j ava:330)
11:08:05,444 ERROR [STDERR] at org.jboss.ejb.plugins.CallValidationInterceptor.in voke(CallValidationInterceptor.java:63)
11:08:05,444 ERROR [STDERR] at org.jboss.ejb.plugins.AbstractTxInterceptor.invoke Next(AbstractTxInterceptor.java:121)
11:08:05,444 ERROR [STDERR] at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTran sactions(TxInterceptorCMT.java:350)
11:08:05,444 ERROR [STDERR] at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxIn terceptorCMT.java:181)
11:08:05,444 ERROR [STDERR] at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInt erceptor.java:205)
11:08:05,444 ERROR [STDERR] at org.jboss.ejb.plugins.ProxyFactoryFinderIntercepto r.invoke(ProxyFactoryFinderInterceptor.java:136)
11:08:05,444 ERROR [STDERR] at org.jboss.ejb.SessionContainer.internalInvoke(Sess ionContainer.java:648)
11:08:05,444 ERROR [STDERR] at org.jboss.ejb.Container.invoke(Container.java:954)
11:08:05,444 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
11:08:05,444 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
11:08:05,444 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
11:08:05,444 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
11:08:05,444 ERROR [STDERR] at org.jboss.mx.interceptor.ReflectedDispatcher.invok e(ReflectedDispatcher.java:155)
11:08:05,444 ERROR [STDERR] at org.jboss.mx.server.Invocation.dispatch(Invocation .java:94)
11:08:05,444 ERROR [STDERR] at org.jboss.mx.server.Invocation.invoke(Invocation.j ava:86)
11:08:05,444 ERROR [STDERR] at org.jboss.mx.server.AbstractMBeanInvoker.invoke(Ab stractMBeanInvoker.java:264)
11:08:05,444 ERROR [STDERR] at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanSe rverImpl.java:659)
11:08:05,444 ERROR [STDERR] at org.jboss.invocation.jrmp.server.JRMPInvoker$MBean ServerAction.invoke(JRMPInvoker.java:819)
11:08:05,444 ERROR [STDERR] at org.jboss.invocation.jrmp.server.JRMPInvoker.invok e(JRMPInvoker.java:420)
11:08:05,444 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
11:08:05,444 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
11:08:05,444 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
11:08:05,444 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
11:08:05,444 ERROR [STDERR] at sun.rmi.server.UnicastServerRef.dispatch(UnicastSe rverRef.java:294)
11:08:05,444 ERROR [STDERR] at sun.rmi.transport.Transport$1.run(Transport.java:1 53)
11:08:05,444 ERROR [STDERR] at java.security.AccessController.doPrivileged(Native Method)
11:08:05,444 ERROR [STDERR] at sun.rmi.transport.Transport.serviceCall(Transport. java:149)
11:08:05,444 ERROR [STDERR] at sun.rmi.transport.tcp.TCPTransport.handleMessages( TCPTransport.java:460)
11:08:05,444 ERROR [STDERR] at sun.rmi.transport.tcp.TCPTransport$ConnectionHandl er.run(TCPTransport.java:701)
11:08:05,444 ERROR [STDERR] at java.lang.Thread.run(Thread.java:595)
11:08:05,444 ERROR [STDERR] Caused by: java.sql.SQLException: Field 'Cliente_upk' doesn't have a default value
11:08:05,444 ERROR [STDERR] at com.mysql.jdbc.SQLError.createSQLException(SQLErro r.java:946)
11:08:05,444 ERROR [STDERR] at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.ja va:2822)
11:08:05,444 ERROR [STDERR] at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:15 36)
11:08:05,444 ERROR [STDERR] at com.mysql.jdbc.ServerPreparedStatement.serverExecu te(ServerPreparedStatement.java:1159)
11:08:05,444 ERROR [STDERR] at com.mysql.jdbc.ServerPreparedStatement.executeInte rnal(ServerPreparedStatement.java:684)
11:08:05,444 ERROR [STDERR] at com.mysql.jdbc.PreparedStatement.executeUpdate(Pre paredStatement.java:1184)
11:08:05,444 ERROR [STDERR] at com.mysql.jdbc.PreparedStatement.executeUpdate(Pre paredStatement.java:1101)
11:08:05,444 ERROR [STDERR] at com.mysql.jdbc.PreparedStatement.executeUpdate(Pre paredStatement.java:1086)
11:08:05,444 ERROR [STDERR] at org.jboss.resource.adapter.jdbc.WrappedPreparedSta tement.executeUpdate(WrappedPreparedStatement.java :251)
11:08:05,444 ERROR [STDERR] at org.jboss.ejb.plugins.cmp.jdbc.keygen.JDBCMySQLCre ateCommand.executeInsert(JDBCMySQLCreateCommand.ja va:107)
11:08:05,444 ERROR [STDERR] at org.jboss.ejb.plugins.cmp.jdbc.JDBCAbstractCreateC ommand.performInsert(JDBCAbstractCreateCommand.jav a:321)
11:08:05,444 ERROR [STDERR] ... 70 more
  #7 (permalink)  
Antiguo 19/09/2006, 08:31
Avatar de hugo777  
Fecha de Ingreso: enero-2002
Ubicación: Lima, Perú
Mensajes: 757
Antigüedad: 22 años, 3 meses
Puntos: 1
Hola, me parece que el método create() que has implementado debería tener el número de columnas que esperas para crear un cliente.

Según veo la excepción es del tipo SQL:

java.sql.SQLException: Field 'Cliente_upk' doesn't have a default value

Y al parecer , es porque al momento de insertar alguno de los campos no tiene un valor.
Modifica tu método create() para enviarle las columnas, o cambia las restricciones de tu tabla para insertar un cliente con datos nulos.
__________________
Saludos,

H@C..
  #8 (permalink)  
Antiguo 19/09/2006, 11:13
Avatar de pyanqn  
Fecha de Ingreso: noviembre-2005
Mensajes: 331
Antigüedad: 18 años, 5 meses
Puntos: 8
Si. lo que hice fue indicarle que no requiera parametros el metodo create(). de todas formas, el error es exactamente el mismo.
  #9 (permalink)  
Antiguo 19/09/2006, 12:19
 
Fecha de Ingreso: marzo-2006
Mensajes: 54
Antigüedad: 18 años, 1 mes
Puntos: 0
me parece que ya tienes una tabla Cliente creada en la base de datos y me parece tambien q esa tabla tiene otras columnas ademas de:
id_cliente, graciaCliente, dirCliente
de hecho quizas tenga una columna llamada 'Cliente_upk' que no admite valores nulos y tiene valor por defecto.
si es asi entonces el JBoss mapea el Entity contra esa tabla, pero al tratar de crear un nuevo registro se produce una excepcion SQL debido a las restricciones que hay sobre la columna 'Cliente_upk' ya que al no tener el Entity un campo que se mapee contra esa columna trata de insertar un valor nulo.
si ese es el problema la solucion seria cambiar el disenno de la tabla (eliminar las columnas que no sean campos del entity o permitir q tengan valores nulos) o utilizar otra tabla o crear campos en el entity q representes esas columnas.


por cierto, me extranna q tu descriptor 'jbosscmp-jdbc' no tenga el mapeo en cuanto a los tipos de datos:
<cmp-field>
<field-name>id</field-name>
<column-name>id</column-name>

<!-- ESTOS DE AKI ABAJO -->
<jdbc-type>BIGINT</jdbc-type>
<sql-type>BIGINT(20)</sql-type>

<auto-increment/>
</cmp-field>

y tambien me extranna en tu descriptor 'ejb-jar' que consideres a la llave primaria un Object:
<prim-key-class>java.lang.Object</prim-key-class>
cuando en realidad es un java.lang.Integer


considera las cosas q te he escrito y dime como te fue.
  #10 (permalink)  
Antiguo 20/09/2006, 05:31
Avatar de pyanqn  
Fecha de Ingreso: noviembre-2005
Mensajes: 331
Antigüedad: 18 años, 5 meses
Puntos: 8
Bien gracias... Pero

Los campos (3) que indique mas arriba son los unicos que existen en mi tabla, y el unico que no acepta nulos es la clave principal "id_cliente"

En el desciptor el mapeo no indica los tipos de datos a cuasa de que este descriptos fue generado automaticamente por JBuilder, de todas formas cuando no se trata de claves autonumeradas todo funciona bien, revisare.

Por otro lado indicar que la clave principal es Object cuando en realidad es Integer es por el caso especial que se detalla en la especificación de claves de J2EE. aqui un link http://www.jguru.com/faq/view.jsp?EID=807820

Te pido por favor revises esta data y volvere a informar de mis novedades

Uso EJB 2.0
  #11 (permalink)  
Antiguo 20/09/2006, 05:50
Avatar de pyanqn  
Fecha de Ingreso: noviembre-2005
Mensajes: 331
Antigüedad: 18 años, 5 meses
Puntos: 8
Despues de regenerar el descriptor quedo:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jbosscmp-jdbc PUBLIC "-//JBoss//DTD JBOSSCMP-JDBC 4.0//EN" "http://www.jboss.org/j2ee/dtd/jbosscmp-jdbc_4_0.dtd">

<jbosscmp-jdbc>
<defaults>
<datasource>java:/MySqlDS</datasource>
<datasource-mapping>mySQL</datasource-mapping>
<create-table>false</create-table>
<alter-table>false</alter-table>
<remove-table>false</remove-table>
<read-only>false</read-only>
<row-locking>true</row-locking>
<unknown-pk>
<unknown-pk-class>java.lang.Integer</unknown-pk-class>
<field-name>idCliente</field-name>
<read-only>false</read-only>
<column-name>id_cliente</column-name>
<jdbc-type>INTEGER</jdbc-type>
<sql-type>INTEGER</sql-type>
<auto-increment />
</unknown-pk>
</defaults>
<enterprise-beans>
<entity>
<ejb-name>Cliente</ejb-name>
<datasource>MySqlDS</datasource>
<datasource-mapping>mySQL</datasource-mapping>
<table-name>cliente</table-name>
<cmp-field>
<field-name>graciaCliente</field-name>
<read-only>false</read-only>
<column-name>gracia_cliente</column-name>
<jdbc-type>VARCHAR</jdbc-type>
<sql-type>VARCHAR</sql-type>
</cmp-field>
<cmp-field>
<field-name>dirCliente</field-name>
<read-only>false</read-only>
<column-name>dir_cliente</column-name>
<jdbc-type>VARCHAR</jdbc-type>
<sql-type>VARCHAR</sql-type>
</cmp-field>
<cmp-field>
<field-name>idCliente</field-name>
<read-only>false</read-only>
<column-name>id_cliente</column-name>
<not-null />
<jdbc-type>INTEGER</jdbc-type>
<sql-type>INTEGER</sql-type>
<auto-increment />
</cmp-field>
<unknown-pk>
<unknown-pk-class>java.lang.Integer</unknown-pk-class>
<column-name>id_cliente</column-name>
<jdbc-type>INTEGER</jdbc-type>
<sql-type>INTEGER</sql-type>
</unknown-pk>
<entity-command name="mysql-get-generated-keys" />
</entity>
</enterprise-beans>
</jbosscmp-jdbc>
  #12 (permalink)  
Antiguo 20/09/2006, 06:23
Avatar de pyanqn  
Fecha de Ingreso: noviembre-2005
Mensajes: 331
Antigüedad: 18 años, 5 meses
Puntos: 8
ciertamente con este ultimo descriptor el error el sel siguiente:

date=200605151000)] Started in 42s:578ms
09:17:28,326 INFO [EJBDeployer] Undeploying: file:/C:/Archivos de programa/jboss-4.0.4.GA/server/hcontrera/deploy/OrdenesDeCompra.jar
09:17:28,357 INFO [BaseLocalProxyFactory] Unbind EJB LocalHome 'Cliente' from jndi 'Cliente'
09:17:28,373 INFO [ProxyFactory] Unbind EJB Home 'FacadeCliente' from jndi 'FacadeCliente'
09:17:28,404 INFO [EjbModule] Undeployed FacadeCliente
09:17:28,404 INFO [EjbModule] Undeployed Cliente
09:17:28,623 INFO [EjbModule] Deploying Cliente
09:17:28,638 INFO [EjbModule] Deploying FacadeCliente
09:17:28,779 INFO [BaseLocalProxyFactory] Bound EJB LocalHome 'Cliente' to jndi 'Cliente'
09:17:28,826 INFO [ProxyFactory] Bound EJB Home 'FacadeCliente' to jndi 'FacadeCliente'
09:17:29,123 INFO [EJBDeployer] Deployed: file:/C:/Archivos de programa/jboss-4.0.4.GA/server/hcontrera/deploy/OrdenesDeCompra.jar
09:18:24,998 INFO [STDOUT] EJB Entity CMP Cliente ENONTRADO...
09:18:30,123 ERROR [Cliente] Could not create entity
java.sql.SQLException: Field 'Cliente_upk' doesn't have a default value
at com.mysql.jdbc.SQLError.createSQLException(SQLErro r.java:946)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.ja va:2822)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:15 36)
at com.mysql.jdbc.ServerPreparedStatement.serverExecu te(ServerPreparedStatement.java:1159)
at com.mysql.jdbc.ServerPreparedStatement.executeInte rnal(ServerPreparedStatement.java:684)
at com.mysql.jdbc.PreparedStatement.executeUpdate(Pre paredStatement.java:1184)
at com.mysql.jdbc.PreparedStatement.executeUpdate(Pre paredStatement.java:1101)
at com.mysql.jdbc.PreparedStatement.executeUpdate(Pre paredStatement.java:1086)
at org.jboss.resource.adapter.jdbc.WrappedPreparedSta tement.executeUpdate(WrappedPreparedStatement.java :251)
at org.jboss.ejb.plugins.cmp.jdbc.JDBCAbstractCreateC ommand.executeInsert(JDBCAbstractCreateCommand.jav a:365)
at org.jboss.ejb.plugins.cmp.jdbc.JDBCAbstractCreateC ommand.performInsert(JDBCAbstractCreateCommand.jav a:321)
at org.jboss.ejb.plugins.cmp.jdbc.JDBCAbstractCreateC ommand.execute(JDBCAbstractCreateCommand.java:151)
at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.cr eateEntity(JDBCStoreManager.java:587)
at org.jboss.ejb.plugins.CMPPersistenceManager.create Entity(CMPPersistenceManager.java:237)
at org.jboss.resource.connectionmanager.CachedConnect ionInterceptor.createEntity(CachedConnectionInterc eptor.java:225)
at org.jboss.ejb.EntityContainer.createLocalHome(Enti tyContainer.java:618)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.invocation.Invocation.performCall(Invoca tion.java:359)
at org.jboss.ejb.EntityContainer$ContainerInterceptor .invokeHome(EntityContainer.java:1130)
at org.jboss.ejb.plugins.AbstractInterceptor.invokeHo me(AbstractInterceptor.java:105)
at org.jboss.ejb.plugins.EntitySynchronizationInterce ptor.invokeHome(EntitySynchronizationInterceptor.j ava:203)

Otra vez lo mismo. No se que hacer, donde esta el problema?

Me podrias enviar un descriptor que funcione para un caso similar...
Gracias
  #13 (permalink)  
Antiguo 20/09/2006, 10:25
 
Fecha de Ingreso: octubre-2003
Mensajes: 3.578
Antigüedad: 20 años, 6 meses
Puntos: 51
De primeras ya te lo ha dicho Hugo:
Cita:
java.sql.SQLException: Field 'Cliente_upk' doesn't have a default value
Ese es el error, seguramente por que una tabla tiene ese campo a NOT NULL y si no lo mapeas en ningun lado ni le das valor... pues casca fijo.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 05:58.