2 Replies Latest reply on Sep 17, 2004 3:17 AM by tonno01

    DB population during deployment

    tonno01 Newbie

      I would like to know, if there is any way to populate a table which gets created during CMP EJB deployment...

      Hope anyone knows an answer.

      Thanks,
      Martin

        • 1. Re: DB population during deployment
          Kabir Khan Master

          You can put a SQL statement into the post-table-create element of your jbosscmp-jdbc.xml file. See chapter 11 of the docs or JBOSS_HOME/docs/dtd/jbosscmp_jdbc_<YOUR_VERSION>.dtd for info.

          Or if you're feeling lazy, here's an example:

          <jbosscmp-jdbc>
          <enterprise-beans>
           <entity>
           <ejb-name>First</ejb-name>
           <post-table-create>
           <sql-statement>insert into First VALUES(1, 'XYZ')</sql-statement>
           </post-table-create>
           </entity>
           <entity>
           <ejb-name>Other</ejb-name>
           <post-table-create>
           <sql-statement>insert into Other VALUES(1, 'blah')</sql-statement>
           <sql-statement>insert into Other VALUES(2, 'blahblah')</sql-statement>
           </post-table-create>
           </entity>
          </enterprise-beans>
          </jbosscmp-jdbc>


          • 2. Re: DB population during deployment
            tonno01 Newbie

            I am trying in this way but it seems not to work correctly. I am using jboss 3.2.5. the post create table sql statements are executed by the first entity bean and then again by the next one, which issues an error as it tries to insert again with the same primary key. why that??
            I ve added the post table create tag also to a relation table mapping but there it doesn't do anything... here is this part of my jbosscmp-jdbc.xml:

            <relation-table-mapping>
            <table-name>RelTable</table-name>
            <create-table>true</create-table>
            <remove-table>false</remove-table>
            <post-table-create>
            <sql-statement>INSERT INTO RelTable VALUES (dd, dd)</sql-statement>
            <sql-statement>INSERT INTO RelTable VALUES (asf, sdf)</sql-statement>
            <sql-statement>INSERT INTO RelTableVALUES (sf, sf)</sql-statement>
            </post-table-create>
            </relation-table-mapping>

            whats wrong???