2 Replies Latest reply on Apr 12, 2015 11:43 AM by Nenad Bulatovic

    JBoss 4.0.2 not altering schema

    Nenad Bulatovic Newbie

      I am reading good old "JBoss - A Developer's Notebook" which describes JBoss 4.0.2. Yes I know it's old, but recently I got involved into project which still uses 4.2 GA so this book is the closest match. Anyway, everything goes fine until I rached page 116/177 (91 - 94) managing schema, where I am supposed to uncomment those two lines in TaskBean.java:

      /**

      * @ejb.persistence

      * @ejb.interface-method

      */

      public abstract int getPriority( );

      /** @ejb.interface-method */

      public abstract void setPriority(int priority);

       

      and after that I should do: ant -Doptional.dd=cmp main deploy

      and JBoss should:

       

      JBoss has added a new priority column to the TASK table. You can verify it through the database manager. If you still have it running, you’ll need to refresh the schema view by selecting Refresh Tree from the View menu.

      Schema updates are logged at the WARN level, so you will see a notice of the change in the console log:

      16:44:44,765 WARN [Task] ALTER TABLE TASK ADD COLUMN priority INTEGER NOT NULL

      For illustrative purposes, you can remove the getPriority and setPriority methods from TaskBean, returning it to its original state, and redeploy the application again. This time JBoss will notice that the field is missing and will remove the priority column:

      16:46:57,339 WARN [Task] ALTER TABLE TASK DROP COLUMN PRIORITY

       

      But it doesn't happen. New "priority" column is not created. What should I do about it? I guess it must be some setting that I might accidentally turned off or something else...

        • 1. Re: JBoss 4.0.2 not altering schema
          jaikiran pai Master

          Which database is this? And what exactly happens when you run that command:

           

          ant -Doptional.dd=cmp main deploy

          • 2. Re: JBoss 4.0.2 not altering schema
            Nenad Bulatovic Newbie

            In first part of the book Hypersonic DB is used.Then author explain how to setup MySQL (and I did that).

            After a while author says to do the following:

             

            To set the flag, you’ll need a jbosscmp-jdbc.xml file with all three flags

            set to true:

            <!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>

            <create-table>true</create-table>

            <alter-table>true</alter-table>

            <remove-table>true</remove-table>

            </defaults>

            </jbosscmp-jdbc>

             

            You’ll find this file in the etc/cmp directory of the ToDo project. To make sure it is included in the deployed application, set the optional.dd flag to cmp when building:

            [todo]$ ant -Doptional.dd=cmp main deploy



            This step will actually BREAK connection with MySQL, and lose authentication.

            So I had to do:

             

            ant undeploy

            ant -Doptional.dd=mysql, -Doptional.dd=security, -Doptional.dd=cmp main deploy

             

            to get back SSL authentication, and after that I was able to login in my own application, but not anymore in version with MySQL but in verision with Hypersonic DB.

             

            Anyway, after: ant -Doptional.dd=cmp main deploy author says to do the following:

             

            Now we’ll explore the table modification capabilities. For that, you’ll need to turn off remove-table. Edit jbosscmp-jdbc.xml as shown here:

             

            <!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>

            <create-table>true</create-table>

            <alter-table>true</alter-table>

            <remove-table>false</remove-table>

            </defaults>

            </jbosscmp-jdbc>

             

            Redeploy the application to make sure that it is in a state where the tables won’t be removed. It will also be helpful to add some tasks in the application to see that your data is preserved, even through schema updates.

            To change to the schema, we’ll add a priority field to TaskBean. Doing that is quite painless. You’ll need to add the following abstract getter and setter methods, with the appropriate XDoclet attributes, to TaskBean.java:

             

            /**

            * @ejb.persistence

            * @ejb.interface-method

            */

            public abstract int getPriority( );

            /** @ejb.interface-method */

            public abstract void setPriority(int priority);

            Build and deploy the application again, just as you did earlier:

             

            [todo]$ ant -Doptional.dd=cmp main deploy

             

            JBoss has added a new priority column to the TASK table. You can verify it through the database manager. If you still have it running, you’ll need to refresh the schema view by selecting Refresh Tree from the View menu. Schema updates are logged at the WARN level, so you will see a

            notice of the change in the console log: 16:44:44,765 WARN [Task] ALTER TABLE TASK ADD COLUMN priority INTEGER NOT NULL

             

            As he is suggesting "You can verify it through the database manager. If you still have it running, you’ll need to refresh the schema view by selecting Refresh Tree from the View menu" I think that the is aware that after those steps application will revert from MySQL to HypersonicDB version of application.

             

            Anyway, back to your question: right after ant -Doptional.dd=cmp main deploy here is what happens:

             

            ant undeploy

            ant -Doptional.dd=cmp main deploy

             

            C:\book\projects\todo>ant -Doptional.dd=cmp main deploy

            Buildfile: build.xml

             

            init:

            webdoclet:

            [webdoclet] (XDocletMain.start                   47  ) Running <deploymentdescriptor/>

            ejbdoclet:

            [ejbdoclet] (XDocletMain.start                   47  ) Running <deploymentdescriptor/>

            [ejbdoclet] Generating EJB deployment descriptor (ejb-jar.xml).

            [ejbdoclet] (XDocletMain.start                   47  ) Running <homeinterface/>

            [ejbdoclet] (XDocletMain.start                   47  ) Running <remoteinterface/>

            [ejbdoclet] (XDocletMain.start                   47  ) Running <localinterface/>

            [ejbdoclet] Generating Local interface for 'com.oreilly.jbossnotebook.todo.ejb.TaskBean'.

            [ejbdoclet] (XDocletMain.start                   47  ) Running <localhomeinterface/>

            [ejbdoclet] Generating Local Home interface for 'com.oreilly.jbossnotebook.todo.ejb.TaskBean'.

            [ejbdoclet] (XDocletMain.start                   47  ) Running <utilobject/>

            [ejbdoclet] Generating Util class for 'com.oreilly.jbossnotebook.todo.ejb.TaskBean'.

            [ejbdoclet] (XDocletMain.start                   47  ) Running <valueobject/>

            [ejbdoclet] Generating Value Object class: 'com.oreilly.jbossnotebook.todo.ejb.TaskBean--> com.oreilly.jbossnotebook.todo.ejb.Task'.

            [ejbdoclet] (XDocletMain.start                   47  ) Running <entitycmp/>

            [ejbdoclet] Generating CMP class for 'com.oreilly.jbossnotebook.todo.ejb.TaskBean'.

            [ejbdoclet] (XDocletMain.start                   47  ) Running <session/>

            [ejbdoclet] INFO:    Some classes refer to other classes that were not found among the sources or on the classpath.

            [ejbdoclet]          (Perhaps the referred class doesn't exist? Hasn't been generated yet?)

            [ejbdoclet]          The referring classes do not import any fully qualified classes matching these classes.

            [ejbdoclet]          However, since no packages are imported, xjavadoc has assumed that the referred classes

            [ejbdoclet]          belong to the same package as the referring class. The classes are:

            [ejbdoclet] C:\book\projects\todo\src\com\oreilly\jbossnotebook\todo\ejb\CommentBean.java --> TaskLocal qualified to com.oreilly.jbossnotebook.todo.ejb.TaskLocal

            [ejbdoclet] C:\book\projects\todo\src\com\oreilly\jbossnotebook\todo\ejb\TaskBean.java --> Task qualified to com.oreilly.jbossnotebook.todo.ejb.Task

            [ejbdoclet] C:\book\projects\todo\src\com\oreilly\jbossnotebook\todo\ejb\CommentBean.java --> Comment qualified to com.oreilly.jbossnotebook.todo.ejb.Comment

             

            compile:

                [javac] Compiling 6 source files to C:\book\projects\todo\build\code

                [javac] Note: Some input files use unchecked or unsafe operations.

                [javac] Note: Recompile with -Xlint:unchecked for details.

             

            war-nodep:

            war:

            ejbjar:

                  [jar] Building jar: C:\book\projects\todo\build\jars\todo.jar

             

            ear-nodep:

                  [ear] Building ear: C:\book\projects\todo\build\jars\todo.ear

             

            ear:

             

            build:

             

            main:

             

            deploy:

                 [copy] Copying 1 file to C:\book\jboss402\server\default\deploy

             

            BUILD SUCCESSFUL

            Total time: 7 seconds

            C:\book\projects\todo>