4 Replies Latest reply on Jan 28, 2003 6:20 PM by juhalindfors

    mysterious "attribute specified more than once" with relatio

    kirlen

      Hi folks,

      I'm still a newbie. I can't seem to call create() successfully on any CMP entity bean if it's the "n" part of a 1-n relationship. When I try, I get the following error:

      javax.ejb.EJBException: Could not create entity:java.sql.SQLException: ERROR: Attribute '' specified more than once

      I'm using JBuilder with JBossOpenTool and PostgresQL.

      If I remove the relationship, the creation succeeds.

      Anyone seen anything like this before? All the deployment descriptors look reasonable to me. It seems to me that this error is coming from SQL that JBoss is generating on my behalf. What can I do to figure out what's going on? This kinda smells like a bug. Or maybe a problem with the Postgres-service?

      Any help would be greatly appreciated...

      Kevin

      The rest of the stack trace is:
      java.sql.SQLException: ERROR: Attribute '' specified more than once

      at org.postgresql.core.QueryExecutor.execute(Unknown Source)
      at org.postgresql.Connection.ExecSQL(Unknown Source)
      at org.postgresql.jdbc2.Statement.execute(Unknown Source)
      at org.postgresql.jdbc2.Statement.executeUpdate(Unknown Source)
      at org.postgresql.jdbc2.PreparedStatement.executeUpdate(Unknown Source)
      at org.jboss.resource.adapter.jdbc.local.LocalPreparedStatement.executeUpdate(LocalPreparedStatement.java:308)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCCreateEntityCommand.insertEntity(JDBCCreateEntityCommand.java:196)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCCreateEntityCommand.execute(JDBCCreateEntityCommand.java:131)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.createEntity(JDBCStoreManager.java:527)
      at org.jboss.ejb.plugins.CMPPersistenceManager.createEntity(CMPPersistenceManager.java:253)
      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.createEntity(CachedConnectionInterceptor.java:270)
      at org.jboss.ejb.EntityContainer.createLocalHome(EntityContainer.java:568)
      at java.lang.reflect.Method.invoke(Native Method)
      at org.jboss.ejb.EntityContainer$ContainerInterceptor.invokeHome(EntityContainer.java:1048)
      at org.jboss.ejb.plugins.AbstractInterceptor.invokeHome(AbstractInterceptor.java:73)
      at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invokeHome(EntitySynchronizationInterceptor.java:209)
      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invokeHome(CachedConnectionInterceptor.java:215)
      at org.jboss.ejb.plugins.EntityInstanceInterceptor.invokeHome(EntityInstanceInterceptor.java:88)
      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:112)
      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:184)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome(TxInterceptorCMT.java:58)
      at org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(SecurityInterceptor.java:105)
      at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:131)
      at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invokeHome(ProxyFactoryFinderInterceptor.java:125)
      at org.jboss.ejb.EntityContainer.invokeHome(EntityContainer.java:475)
      at org.jboss.ejb.plugins.local.BaseLocalProxyFactory.invokeHome(BaseLocalProxyFactory.java:271)
      at org.jboss.ejb.plugins.local.LocalHomeProxy.invoke(LocalHomeProxy.java:110)
      at $Proxy66.create(Unknown Source)
      ...

        • 1. Re: mysterious "attribute specified more than once" with rel
          kirlen

          Well, I figured out the "mystery". It's taken awhile to get my head around the fact that you can't have a "container managed" relationship based on a foreign key and also specify that key as an entity bean field. That's what causes the container to generate two SQL references to the same field.

          I'm still confused about one thing, though. Isn't it common to want to have a 1-many relationship between tables where the primary key on the "many" side is a combination of some field AND the foreign key on which you want the relationship to be based?

          For example, what about an Orders tables, with primary key OrderID, and an OrderItems table, with primary key OrderID+OrderLineNumber. The OrderLineNumber does not uniquely identify an OrderItem, but it does when combined with OrderID. But apparently you can't have a container-managed relationship here, because OrderID, as part of the compound primary key for the OrderItems table, must be a plain old container-managed field. Is this a limitation of CMP?

          As far as I can tell, the only way to workaround this is to force all tables to have their own unique ID field, so that foreign keys are free to participate in CMRs. This seems wasteful if there is a "natural" compound primary key that could be used.

          Anyone else struggled with this?

          Thanks,

          Kevin

          • 2. Re: mysterious "attribute specified more than once" with rel
            icordoba

            Hi there,
            did you find a sollution for this?
            I am facing to it continuously as my SQL tables usually have a foreign key in their primrary key.
            I've been working with Pramati J2EE server and solves this without any problem... in fact it doesn't treats it as a problem...

            • 3. Re: mysterious "attribute specified more than once" with rel
              kirlen

              No. For the moment I'm doing without relationships. I think I'll want them eventually though, so I was planning on just using a "redundant" primary key :(

              • 4. Re: mysterious "attribute specified more than once" with rel