Announcement Announcement Module
Collapse
No announcement yet.
Using an Abstract Entity base and providing version and id fields Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using an Abstract Entity base and providing version and id fields

    Following on from this thread http://forum.springsource.org/showthread.php?t=77252 I want to provide my own version and id fields for most of my persistent entities so that I can provide XStream annotations on these fields.

    I think the best approach here is to provide an AbstractEntity as a base class; but my experiments show that ROO doesn't seem to remove the fields from the generated aspects in the sub-classes. What is the correct way to do this? Do I need to annotate the Abstract class as a RooEntity? Do I have to proved public getters and setters for these fields? I'm also getting warnings like this in the shell 'User provided @javax.persistence.Id field but failed to provide a public 'getId()' method'

    Jon

  • #2
    Jon,

    Can you share the script you are using? Roo should remove the fields from the generated aspects in the sub-classes. If you take a look at the code generated by the sample clinic.roo script you will see that AbstractPerson contains an id and version but not the inheriting Owner...

    -Stefan

    Comment


    • #3
      Hi Stefan

      Initially I hadn't annotated the AbstractEntity with @RooEntity. It also seems that sometimes I have to 'reboot' the ROO shell in order for it to manage some of the aspect files. I'm not sure what the pattern is, I'll try and come back with something a little more concrete later. All is well for now.

      Jon

      Comment


      • #4
        I'm having trouble with this, too. Note that this is for a "master" base entity and is not part of the model in any way.

        Here are the (hopefully) reproduceable steps (done with latest build, 359):

        Run the following commands in a new Roo project directory:
        Code:
        project --topLevelPackage com.abstracttest --projectName abstracttest
        
        persistence setup --database HYPERSONIC_IN_MEMORY --provider HIBERNATE
        
        class --name ~.domain.AbstractBaseEntity --abstract
        field number id --type java.lang.Long
        field number version --type java.lang.Integer
        Exit Roo and "fix up" AbstractBaseEntity with annotations:
        Code:
        package com.abstracttest.domain;
        
        import javax.persistence.Id;
        import javax.persistence.GeneratedValue;
        import javax.persistence.Column;
        import javax.persistence.Version;
        import javax.persistence.GenerationType;
        import javax.persistence.MappedSuperclass;
        
        @MappedSuperclass
        public abstract class AbstractBaseEntity {
        
        
            @Id    
            @GeneratedValue(strategy = GenerationType.AUTO)    
            @Column(name = "id")    
            private Long id;    
            
            @Version    
            @Column(name = "version")    
            private Integer version;   
        	}
        Re-enter Roo and add a new entity that extends AbstractBaseEntity:

        Code:
        roo> entity --name ~.domain.Person --extends ~.domain.AbstractBaseEntity
        The response I get is this:
        Code:
        Created SRC_MAIN_JAVA\com\abstracttest\domain\Person.java
        Undo create SRC_MAIN_JAVA\com\abstracttest\domain\Person.java
        User provided @javax.persistence.Id field but failed to provide a public 'getId()' method in 'com.abstracttest.domain.Person'
        roo>
        I've also noticed that if I create the Person entity before annotating the AbstractBaseEntity, Roo generates "_id" and "_version" fields on Person_Roo_Entity.aj instead of using the "id" and "version" fields set in AbstractBaseEntity.

        Comment


        • #5
          Added to issue tracker: https://jira.springsource.org/browse/ROO-317

          Comment

          Working...
          X