Problem home.create() for an Entity with relationship 1:N
zemaria Sep 12, 2002 12:42 AMHello.
I have created a relationship 1:N and when a try to create (InterfaceHome.create()) an Entity Bean the side 1 i get the follow error message in jboss console:
00:44:50,241 ERROR [lojaVirtual/Produto] Could not create entity
java.sql.SQLException: [Microsoft][SQLServer JDBC Driver][SQLServer]Column name 'categoria' appears
more than once in the result column list.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processErrorToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReplyToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRPCRequest.processReplyToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown Source)
at com.microsoft.jdbc.sqlserver.SQLServerImplStatement.getNextResultType(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.commonExecute(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.executeInternal(Unknown Source)
at com.microsoft.jdbc.base.BasePreparedStatement.execute(Unknown Source)
at com.microsoft.jdbc.base.BasePreparedStatement.executeUpdate(Unknown Source)
at org.jboss.resource.adapter.jdbc.local.LocalPreparedStatement.executeUpdate(LocalPreparedS
tatement.java:308)
at org.jboss.ejb.plugins.cmp.jdbc.JDBCCreateEntityCommand.insertEntity(JDBCCreateEntityComma
nd.java:196)
at org.jboss.ejb.plugins.cmp.jdbc.JDBCCreateEntityCommand.execute(JDBCCreateEntityCommand.ja
va:131)
at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.createEntity(JDBCStoreManager.java:450)
at org.jboss.ejb.plugins.CMPPersistenceManager.createEntity(CMPPersistenceManager.java:253)
at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.createEntity(CachedConne
ctionInterceptor.java:270)
at org.jboss.ejb.EntityContainer.createHome(EntityContainer.java:728)
at java.lang.reflect.Method.invoke(Native Method)
at org.jboss.ejb.EntityContainer$ContainerInterceptor.invokeHome(EntityContainer.java:1116)
at org.jboss.ejb.plugins.AbstractInterceptor.invokeHome(AbstractInterceptor.java:73)
at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invokeHome(EntitySynchronizationIn
terceptor.java:257)
at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invokeHome(CachedConnect
ionInterceptor.java:215)
at org.jboss.ejb.plugins.EntityInstanceInterceptor.invokeHome(EntityInstanceInterceptor.java
:134)
at org.jboss.ejb.plugins.EntityLockInterceptor.invokeHome(EntityLockInterceptor.java:79)
at org.jboss.ejb.plugins.EntityCreationInterceptor.invokeHome(EntityCreationInterceptor.java
:44)
at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:98)
at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:167)
at org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome(TxInterceptorCMT.java:52)
at org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(SecurityInterceptor.java:104)
at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:109)
at org.jboss.ejb.EntityContainer.invokeHome(EntityContainer.java:487)
at org.jboss.ejb.Container.invoke(Container.java:726)
at org.jboss.ejb.EntityContainer.invoke(EntityContainer.java:1055)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:491)
at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:362)
at java.lang.reflect.Method.invoke(Native Method)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:241)
at sun.rmi.transport.Transport$1.run(Transport.java:152)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:148)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:465)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:706)
at java.lang.Thread.run(Thread.java:484)
[ejb-jar.xml]
...
<!-- Relationships -->
<ejb-relation >
<ejb-relation-name>categoria-produto</ejb-relation-name>
<!-- bidirectional -->
<ejb-relationship-role >
<ejb-relationship-role-name>produto</ejb-relationship-role-name>
One
<relationship-role-source >
<ejb-name>lojaVirtual/CategoriaProduto</ejb-name>
</relationship-role-source>
<cmr-field >
<cmr-field-name>produtos</cmr-field-name>
<cmr-field-type>java.util.Set</cmr-field-type>
</cmr-field>
</ejb-relationship-role>
<ejb-relationship-role >
<ejb-relationship-role-name>categoria</ejb-relationship-role-name>
Many
<relationship-role-source >
<ejb-name>lojaVirtual/Produto</ejb-name>
</relationship-role-source>
<cmr-field >
<cmr-field-name>categoria</cmr-field-name>
</cmr-field>
</ejb-relationship-role>
</ejb-relation>
...
[jbosscmp-jdbc.xml]
...
<ejb-relation>
<ejb-relation-name>categoria-produto</ejb-relation-name>
<foreign-key-mapping/>
<ejb-relationship-role>
<ejb-relationship-role-name>produto</ejb-relationship-role-name>
<key-fields>
<key-field>
<field-name>codigo</field-name>
<column-name>categoria</column-name>
</key-field>
</key-fields>
</ejb-relationship-role>
<ejb-relationship-role>
<ejb-relationship-role-name>categoria</ejb-relationship-role-name>
<key-fields/>
</ejb-relationship-role>
</ejb-relation>
...
[SQL Server Script]
CREATE TABLE [dbo].[CategoriaProduto] (
[codigo] [numeric](3, 0) NOT NULL ,
[Descricao] [varchar] (50) NOT NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[CategoriaProduto] WITH NOCHECK ADD
CONSTRAINT [PK_CategoriaProduto] PRIMARY KEY CLUSTERED
(
[codigo]
) ON [PRIMARY]
CREATE TABLE [dbo].[Produto] (
[codigo] [numeric](5, 0) NOT NULL ,
[descricao] [varchar] (50) NOT NULL ,
[preco] [numeric](5, 2) NOT NULL ,
[categoria] [numeric](3, 0) NOT NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[Produto] WITH NOCHECK ADD
CONSTRAINT [PK_Produto] PRIMARY KEY CLUSTERED
(
[codigo]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[Produto] ADD
CONSTRAINT [FK_Produto_CategoriaProduto] FOREIGN KEY
(
[categoria]
) REFERENCES [dbo].[CategoriaProduto] (
[codigo]
) ON DELETE CASCADE
GO
I have tested the relationship and they are work nice.
Sorry about my english. I am a brazilian.