Results 1 to 5 of 5

Thread: Using an Abstract Entity base and providing version and id fields

  1. #1

    Default 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. #2
    Join Date
    Mar 2008
    Location
    Sydney, AU
    Posts
    974

    Default

    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

  3. #3

    Default

    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

  4. #4
    Join Date
    Sep 2009
    Posts
    101

    Default

    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.

  5. #5
    Join Date
    Sep 2009
    Posts
    101

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •