3 Replies Latest reply on Mar 26, 2009 2:56 AM by swd847

    Seamgen reverse engineer, too many xml?

    philip142au.philip_andrew.hotmail.com

      Hi,


      I have a seam-gen.reveng.xml file but I keep having to write the same XML over and over.


      Is there a way to merge all this xml? I only want the onCreate and onUpdate so I can record the date time, for a lot of tables (not every table).


      Thanks, Philip


        <table name="ticket" catalog="artawardscheme">
          <meta attribute="extra-import">javax.persistence.*</meta>
           <meta attribute="class-code">
      @PrePersist
      public void onCreate()
      {
      created = new Date();
      updated = new Date();
      }

      @PreUpdate
      public void onUpdate()
      {
        updated = new Date();
      }
           </meta>
        </table>
        <table name="user" catalog="artawardscheme">
          <meta attribute="extra-import">javax.persistence.*</meta>
           <meta attribute="class-code">
      @PrePersist
      public void onCreate()
      {
      created = new Date();
      updated = new Date();
      }

      @PreUpdate
      public void onUpdate()
      {
        updated = new Date();
      }
            
           </meta>
        </table>


        • 1. Re: Seamgen reverse engineer, too many xml?
          philip142au.philip_andrew.hotmail.com
          Sorry that didn't format correctly.

            <table name="ticket" catalog="artawardscheme">
              <meta attribute="extra-import">javax.persistence.*</meta>
               <meta attribute="class-code">
          @PrePersist
          public void onCreate()
          {
          created = new Date();
          updated = new Date();
          }

          @PreUpdate
          public void onUpdate()
          {
            updated = new Date();
          }
               </meta>
            </table>
            <table name="user" catalog="artawardscheme">
              <meta attribute="extra-import">javax.persistence.*</meta>
               <meta attribute="class-code">
          @PrePersist
          public void onCreate()
          {
          created = new Date();
          updated = new Date();
          }

          @PreUpdate
          public void onUpdate()
          {
            updated = new Date();
          }
                
               </meta>
            </table>
          • 2. Re: Seamgen reverse engineer, too many xml?
            swd847

            Use a generic entityListener for all your classes, configured through orm.xml


            orm.xml


            <?xml version="1.0" encoding="UTF-8"?>
            <entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
                             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_1_0.xsd"
                             version="1.0"
                    >
                <persistence-unit-metadata>
                    <persistence-unit-defaults>
                        <entity-listeners>
                            <entity-listener class="com.mypackage.EntityListener">
                                <pre-persist method-name="prePersist"/>
                                <pre-update method-name="preUpdate"/>
                            </entity-listener>
                        </entity-listeners>
                    </persistence-unit-defaults>
                </persistence-unit-metadata>
            
            </entity-mappings>
            



            not sure about the order, pre-update may need to be first.


            The entity is passed to the entityListener method as an argument, so you can set the values there.


            • 3. Re: Seamgen reverse engineer, too many xml?
              swd847

              Also it is possible to hack up the templates that seam gen uses, but that requires a bit more effort.