1 2 Previous Next 20 Replies Latest reply on Jul 11, 2002 4:51 PM by sursha

    entity bean mapping to multiple tables

    sursha

      Hi,
      I am trying to deploy a CMP entitybean which maps to columns in 2 different tables.
      The jaws.xml section for the same looks like below:

      <ejb-name>BankAccountBean</ejb-name>

      <table-name>ES_BANK_ACCOUNT,ES_WALLET_ITEM</table-name>
      <create-table>false</create-table>
      <cmp-field>
      <field-name>bankName</field-name>
      <column-name>ES_BANK_ACCOUNT.BANK_NAME</column-name>
      <jdbc-type>VARCHAR</jdbc-type>
      <sql-type>VARCHAR(30)</sql-type>
      </cmp-field>
      <cmp-field>
      <field-name>description</field-name>
      <column-name>ES_WALLET_ITEM.WALLET_DESC</column-name>
      <jdbc-type>VARCHAR</jdbc-type>
      <sql-type>VARCHAR(30)</sql-type>
      </cmp-field>
      .
      .

      etc.

      I get the following error when i run the test client to create the bean.

      [WARN,PreparedStatementFactory] Error creating prepared statement.
      SQL Exception: Syntax error: Encountered "," at line 1, column 28.
      at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:245)

      at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:220)
      at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:122)
      at RmiJdbc.RJConnectionServer_Stub.prepareStatement(Unknown Source)
      at RmiJdbc.RJConnection.prepareStatement(RJConnection.java:109)
      at org.jboss.pool.jdbc.PreparedStatementFactory.createObject(Unknown Source)
      at org.jboss.pool.cache.LeastRecentlyUsedCache.addObject(Unknown Source)
      at org.jboss.pool.cache.LeastRecentlyUsedCache.getObject(Unknown Source)
      at org.jboss.pool.cache.LeastRecentlyUsedCache.useObject(Unknown Source)
      at org.jboss.pool.jdbc.xa.wrapper.XAClientConnection.prepareStatement(Unknown Source)
      at org.jboss.ejb.plugins.jaws.jdbc.JDBCCommand.jdbcExecute(JDBCCommand.java:154)
      at org.jboss.ejb.plugins.jaws.jdbc.JDBCCreateEntityCommand.execute(JDBCCreateEntityCommand.j
      ava:143)
      at org.jboss.ejb.plugins.jaws.JAWSPersistenceManager.createEntity(JAWSPersistenceManager.jav
      a:128)
      at org.jboss.ejb.plugins.CMPPersistenceManager.createEntity(CMPPersistenceManager.java:231)
      at org.jboss.ejb.EntityContainer.createHome(EntityContainer.java:632)
      at java.lang.reflect.Method.invoke(Native Method)
      at org.jboss.ejb.EntityContainer$ContainerInterceptor.invokeHome(EntityContainer.java:859)
      at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invokeHome(EntitySynchronizationIn
      terceptor.java:234)
      at org.jboss.ejb.plugins.EntityInstanceInterceptor.invokeHome(EntityInstanceInterceptor.java
      :147)
      at org.jboss.ejb.plugins.EntityLockInterceptor.invokeHome(EntityLockInterceptor.java:97)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invokeNext(TxInterceptorCMT.java:142)
      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:347)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome(TxInterceptorCMT.java:86)
      at org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(SecurityInterceptor.java:102)
      at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:103)
      at org.jboss.ejb.EntityContainer.invokeHome(EntityContainer.java:421)
      at org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker.invokeHome(JRMPContainerInvoker.ja
      va:387)
      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)

      ---------------------------------------------------

      It throws error saying not able to prepare sql statement as given above.
      It seems JAWS is unable to take more than one table names in the <table-name> tag.

      Could anyone please help me out how to map one entity bean to multiple tables using JBOSS 2.4.4 with tomcat?
      Thanks in advance.

      Suresh



        • 1. Re: entity bean mapping to multiple tables
          dsundstrom

          I don't know of any EJB servers that support this. Switch to CMP 2.0 and create two entites with a one-to-one cascade-delete relationship.

          • 2. Re: entity bean mapping to multiple tables
            sursha

            As far as I know, Websphere and Borland app server supports this.

            • 3. Re: entity bean mapping to multiple tables
              dsundstrom

              I think this type of mapping is kind of lame, but if there is sufficent demand I'll add it. In the mean time you will have to do the joined entity trick or get out your check book.

              • 4. Re: entity bean mapping to multiple tables
                sursha

                I'm thinking of converting all CMPs to BMPs. What you think about it? I can stay away from the mapping issues and hence porting from one app server to another app server becomes easier.

                • 5. Re: entity bean mapping to multiple tables
                  dsundstrom

                  > I'm thinking of converting all CMPs to BMPs. What you
                  > think about it? I can stay away from the mapping
                  > issues and hence porting from one app server to
                  > another app server becomes easier.

                  Try converting one or two. When you get the first 5k lines of code down, you'll come back.

                  As I said, if there is sufficent demand I'll add the mapping, but from what I see, you are the only one interested in this mapping. If you really want it, you can always pay for priority development.

                  • 6. Re: entity bean mapping to multiple tables
                    beagleboy

                    Im just wondering why this functionality is not provided. I only have a small amount of Bean experience but if you want a view into two tables would it not be better/more efficient to only have to instantiate one Bean rather than two. So if you wanted to requrn a large amount of information would having a CMP mapped to two tables not half the amount of Beans instantiated at any one time.
                    Im sure im misunderstanding the use of CMPs in some way so maybe you could clarify this for me....

                    • 7. Re: entity bean mapping to multiple tables
                      sursha

                      Hi,
                      What kind of money you are talking about to add this feature?

                      • 8. Re: entity bean mapping to multiple tables
                        dsundstrom

                        I don't know; I haven't seriously how long it would take, but I have some design ideas. If you are seriously interested, contact sales@jboss.org.

                        As for BegleBoy, if you database supports updateable views, just create a view and map the entity to the view.

                        • 9. Re: entity bean mapping to multiple tables
                          sursha

                          Hi,
                          I have sent an email to sales to find out the details.

                          I like the idea of using updatable views. We're using Cloudscape, DB2 and MS SQL Server 2000.
                          I dont know whether all of them support updatable views?
                          Any ideas?

                          • 10. Re: entity bean mapping to multiple tables
                            dsundstrom

                            SQL Server does, but I have never used the other two. I would bet DB2 does.

                            • 11. Re: entity bean mapping to multiple tables
                              cstone

                              Since it was asked if anyone else is interested in this functionality (CMP mapping of one entity to many tables), I should state for the record that I am!

                              In general, I feel that this capability is fairly important when porting legacy RDB-based systems to newer EJB technology. The reason being that legacy DB schemas are often really clunky from an entity modelling point of view (having organically evolved over long periods of time to fit changing requirements), and there is also a common constraint to not radically change the DB schema for legacy code maintenance / customer support / data-migration issues. Thus, the idea of taking a legacy schema and simply modifying it to fit a sounder EJB-targeted entity model is simply not an option in this real-world scenario.

                              Therefore, it can be a real help to be able to "clean up" the logical entities in the EJB layer and let CMP resolve the complex mapping to the physical legacy schema.

                              I think that the reason that this request has not been too common thus far is that many EJB projects are for new apps (or web-site-based apps having DBs that never get installed into customer sites) that have the liberty of being able to change the schema at will (though it is never a costless operation ;-), in which case it is straightforward enough to make it fit a nice EJB entity model in a one-to-one fashion. However, as EJB gains more acceptance in the marketplace, I think we will find that more companies will add EJB logic on top of old legacy schemas for various reasons. Then one-to-many entity-to-table mapping will become a more popular item.

                              In my particular case, it is pretty important right now; I also feel it is a crucial feature for JBoss architects to anticipate as more requests come in for it.

                              • 12. Re: entity bean mapping to multiple tables
                                dsundstrom

                                It is on the list for JBoss 4.0, but if you want it sooner you can fund the development to have me do it right now. If you are intersted contact sales@jboss.org.

                                • 13. Re: entity bean mapping to multiple tables
                                  ukkm

                                  Hello Dain,

                                  I agree with "cstone" because unfortunately a lot of projects won't setup on a green field. So I think that the mapping to multiple tables in the real project world will be frequently an important criteria for choosing an application server. I don't know when we can discuss about JBoss 4.0 and because I believe in the potential of JBoss I can imagine that this feature could be a big point in competition with the "big players". And what I want to say is that the multiple table mapping feature is surely not the special requirement of "cstone" but it is the constraint of the real project world.

                                  Best regards
                                  Udo

                                  • 14. Re: entity bean mapping to multiple tables
                                    brad

                                    Just for the record, he is far from the only one interested in this mapping.

                                    1 2 Previous Next