1 Reply Latest reply on Oct 28, 2005 1:49 PM by epbernard

    ejb3 ineritance using AccessType.FIELD, howto set class leve

    evrim

      Hi,

      I'm trying to implement a hierachical object base for a project. I'm using ejb3 hibernate inheritance. My RelationalObject represents simple tree node. EnterpriseRelation object extends from RelationalObject and uses Collection children and RelationalObject parent fields from its' superclass.

      My problem is about configuring fetch type of getSites() method. Since it's inherited from superclass, there is no way to configure fetchType.LAZY or EAGER. Is there a way to override this behaviour?

      To make it clear, i want RelationalObject fetchType.LAZY by default, and also, want to be able to override if necessary at subclassess like EnterpriseRelation.

      Thnx.

      package tr.gen.core.entity;
      
      @Entity()
      @Inheritance(
       strategy=InheritanceType.SINGLE_TABLE,
       discriminatorType=DiscriminatorType.STRING,
       discriminatorValue="RelationalObject"
      )
      public class RelationalObject implements Serializable {
       private static final long serialVersionUID = 1L;
      
       protected int id;
       protected RelationalObject parent;
       protected Collection children;
      
       @Id(generate = GeneratorType.AUTO)
       public int getId() {return id;}
       public void setId(int id) { this.id = id; }
      
       @OneToMany(targetEntity=tr.gen.core.entity.RelationalObject.class)
       public Collection getChildren() {return children;}
       public void setChildren(Collection children) {this.children = children; }
      
       @ManyToOne(targetEntity=tr.gen.core.entity.RelationalObject.class)
       public RelationalObject getParent() {return parent; }
       public void setParent(RelationalObject parent) {this.parent = parent;}
      }
      
      


      package tr.gen.core.accounting.entity;
      
      import java.util.Collection;
      
      import javax.persistence.AccessType;
      import javax.persistence.Entity;
      import javax.persistence.Inheritance;
      
      import tr.gen.core.entity.RelationalObject;
      
      @Entity(access = AccessType.FIELD)
      @Inheritance(
       discriminatorValue="EnterpriseRelation"
      )
      public class EnterpriseRelation extends RelationalObject {
       private static final long serialVersionUID = 1L;
      
       public Collection getSites() {
       return getChildren();
       }
       public void setSites(Collection sites) {
       setChildren(sites);
       }
       public Core getCore() {
       return (Core) getParent();
       }
      
       public void setCore(Core core) {
       setParent(core);
       }
      
      }