Announcement Announcement Module
Collapse
No announcement yet.
Why tables of Abstract classes are generated upon perform tests? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Why tables of Abstract classes are generated upon perform tests?

    Here's the roo commands in order.
    Code:
    entity --class ~.domain.AbstractDomain --abstract
    field date --type java.util.Date --fieldName dateCreated --dateTimeFormatPattern "yyyy-MM-dd HH:mm:ss"
    field date --type java.util.Date --fieldName dateUpdated --dateTimeFormatPattern "yyyy-MM-dd HH:mm:ss"
    field boolean --fieldName active
    
    entity --class ~.domain.Employee --extends ~.domain.AbstractDomain --testAutomatically
    field number --type int --fieldName employeeId
    field string --fieldName lastName 
    field string --fieldName firstName 
    field string --fieldName middleName 
    
    perform tests
    I created an AbstractDomain class for common fields of domains. Then when I perform tests the abstract_domain table was created.

    creating an AbstractDomain for common fields are not good practice?
    If yes, would you recommend on how to address common fields of domains?

    thanks

  • #2
    I have a similar issue

    I am also facing similar issue.

    Is this a bug in sring roo? Or should the abstract classes be used in differently?

    Comment


    • #3
      This is Roo's default behaviour. If you want a table per class, use --inheritanceType TABLE_PER_CLASS on the abstract type

      Comment


      • #4
        When I added "--inheritanceType SINGLE_TABLE" to the abstract class, I still got a table generated with the abstract classname.
        As the child class didn't generate any table with its name it made me suspect it's a naming issue. The fields from the child class are within the generated table, so it's not the abstract class.

        Did you guys check the fields present?

        Comment


        • #5
          Sounds normal to me. SINGLE_TABLE is supposed to generate one table containing data from all child classes, see for example here.

          Comment


          • #6
            Originally posted by wallenborn View Post
            Sounds normal to me. SINGLE_TABLE is supposed to generate one table containing data from all child classes
            Yes, you're right, I was mixing it up with mapped superclass for some reason.

            This alternate roo-script generates a result like what the TS seemed to expect
            Code:
            //project --topLevelPackage com.sria.testdrive --projectName sria-mvc-testdrive --java 5
            
            //persistence setup whatever you use
            
            entity --class ~.domain.Person --abstract --mappedSuperclass
            
            field date --type java.util.Date --fieldName dateCreated --dateTimeFormatPattern "yyyy-MM-dd HH:mm:ss"
            field date --type java.util.Date --fieldName dateUpdated --dateTimeFormatPattern "yyyy-MM-dd HH:mm:ss"
            field boolean --fieldName active
            
            entity --class ~.domain.Employee --extends ~.domain.Abstracted --testAutomatically
            //field number --type int --fieldName employeeId //roo handles this automatically with 'id' so I don't see the need
            field string --fieldName lastName 
            field string --fieldName firstName 
            field string --fieldName middleName
            
            perform tests
            However, this is obviously not always the best solution as that depends on your model.

            Comment


            • #7
              This is also a good read on JPA2 as a supplement as Roo uses JPA2:What's new and exciting in JPA2

              Comment


              • #8
                Originally posted by wallenborn View Post
                Sounds normal to me. SINGLE_TABLE is supposed to generate one table containing data from all child classes, see for example here.
                Originally posted by Alan Stewart View Post
                This is Roo's default behaviour. If you want a table per class, use --inheritanceType TABLE_PER_CLASS on the abstract type
                The below statement is from @wallenborn 's link
                Table Per Class Inheritance

                Table per class inheritance allows inheritance to be used in the object model, when it does not exist in the data model. In table per class inheritance a table is defined for each concrete class in the inheritance hierarchy to store all the attributes of that class and all of its superclasses. Be cautious using this strategy as it is optional in the JPA spec, and querying root or branch classes can be very difficult and inefficient.
                I am confused with the following phrases:
                1) "optional in the JPA spec" <- what does it mean?
                2) "querying root or branch classes can be very difficult and inefficient" <- why it become difficult and inefficient, if it treats as one concrete class..

                please share your thoughts on these.
                Thanks

                Comment


                • #9
                  My main goals are:
                  1) to have a common type for all my domain
                  2) to have a common type to access common fields (e.g. getDateCreated(), getDateUpdated, get... set...)
                  3) to have a deepCopyFromSource() method to implement Deep Copy.
                  4) to implements Serializable on the AbstractDomain class (because it requires for MVC binding? if not, I don't have to add implements)

                  If you have other better approach please share it.

                  Thanks and regards.

                  Comment

                  Working...
                  X