Reg: self reference ME

Hi,
I created a class in se24 and in method wrote simple addition logic
I created a object in my prog for the class and entered the numbers it works fine.
But when I use ME to reference the method its showing an error ME is not defined by any DATA statemnt
the code is as follows
class zp_class definition load.
PARAMETERS : p_x type i,
             p_y type i.
data : z type i.
CALL METHOD me->zadd
  EXPORTING
    v_x    = p_x
    v_y    = p_y
  IMPORTING
    v_z    = z
write :z  .
How to make use of ME plz guide me
regards

Hi ,
me is used to refer the methods and attributes of the same class within the methods of that class only.
This will explain by the folllowing example.
*& Report  Z_SIMPLE_CLASS
REPORT  z_simple_class.
      CLASS c1 DEFINITION
CLASS c1 DEFINITION.
  PUBLIC SECTION.
    DATA: a TYPE i value 3,
              b TYPE i value 4.
    METHODS: m_add exporting a type i
                             b type i,
                      m_sub.
ENDCLASS.                    "c1 DEFINITION
CLASS c1 IMPLEMENTATION.
  METHOD m_add.
    DATA c TYPE i.
    c = a + b.
    WRITE: 'c:= ', c.
  ENDMETHOD.                    "m_add
  METHOD m_sub.
    DATA c TYPE i.
    CALL METHOD me->m_add.
    b = c.
    a = b.
    c = a - b.
    WRITE: 'c:= ', c.
  ENDMETHOD.                    "m_sub
ENDCLASS.                    "c1 IMPLEMENTATION
START-OF-SELECTION.
  DATA: cc1 TYPE REF TO c1,
        a1 type i value -4,
        b1 type i value -4.
  CREATE OBJECT cc1.
  cc1->m_add( importing a = a1 b = b1 ).
  write: cc1->a.
  write: cc1->b.
by
Prasad G.V.K
Edited by: PRASAD GVK on Jul 21, 2008 3:03 PM

Similar Messages

  • Why do we need a Self Reference "me" to use the components of a class

    Hi
    I am not clear why do we need a self reference variable "me" to call the components of its own class? when it can be accessed directly as in the following examples?
    In my first example below i can call the method display_name directly without creating a reference object or instance of the class within the class.
    In the second example i am using the self refernce Write me->name to access the component of a class.
    My question is why do we need "me" when i can use the components directly as shown in my first example.
    CLASS egocentric DEFINITION.
      PUBLIC SECTION.
        DATA:
         name(10) TYPE c READ-ONLY.
        METHODS set_name.
        METHODS display_name.
    ENDCLASS.                    "egocentric DEFINITION
    *       CLASS egocentric IMPLEMENTATION
    CLASS egocentric IMPLEMENTATION.
      METHOD set_name.
        MOVE 'Abap Objects' TO name.
        CALL method display_name.
      ENDMETHOD.                    "write_name
      METHOD display_name.
        write: name.
      ENDMETHOD.                    "display_name
    ENDCLASS.                    "egocentric IMPLEMENTATION
    *Global Data
    DATA oref TYPE REF TO egocentric.
    START-OF-SELECTION.
      CREATE OBJECT oref.
      CALL METHOD oref->set_name.
    CLASS egocentric DEFINITION.
            PUBLIC SECTION.
                DATA:
                 name(10) TYPE c VALUE u2018Instructoru2019
    READ-ONLY.
                 METHODS write_name.
    ENDCLASS.
    CLASS egocentric IMPLEMENTATION.
            METHOD write_name.
                WRITE me->name.
            ENDMETHOD.
    ENDCLASS.
    *Global Data
    DATA oref TYPE REF TO egocentric.
    START-OF-SELECTION.
            CREATE OBJECT oref.
            CALL METHOD oref->write_name.

    You can go WIKI and search with ABAP Objects.
    Or do the same in 'advanced search'  and select a search area. You are bound to find something.
    Or this link perhaps:
    [abap objects|http://help.sap.com/saphelp_nw70/helpdata/EN/ce/b518b6513611d194a50000e8353423/content.htm]

  • Resolve self-reference table by alias tables in detail

    Hello Gurus,
            can you tell me how to resolve self-reference table by alias tables in detail?
    Many thanks.

    Hello, for the following step 3, I don't understand, will you please give me some explanation for step 3?
    Save your Staff universe, and test the results in Web Intelligence Rich Client as follows:
    1. Run a query using Manager and Employee. Add a count on both columns.
    2. Add a query with only the Manager object. Add a count. Is this the correct value?
    3. Open your Staff universe in Universe Designer and edit the Manager object. To ensure
    that the data is restricted to only manager data, use the Tables button. Select the
    EMPLOYEE table, to force the object to use the join between the table and restrict the
    data.
    4. Test the result, creating a new query with only the Manager object. It returns the correct
    number of managers.
    5. Edit the query and add Employee. Run and display the count. There are 26 rows. Why?
    The join restricts the data to look only for employees that have managers. However, there
    is a manager that does not have a manager, and is now excluded.
    6. Open your Staff universe in Universe Designer and add an outer join on the MANAGER
    table side.
    7. Save the changes and test the results in Web Intelligence Rich Client.

  • Example of Self Reference

    Hello experts,
    I am totally new to ABAP Objects and was going through a book for the same to learn the concepts.
    There is a section of Self Reference in this book. I could not understand this concept by myself. Could you please help me out to explain this thing.
    PFB the code that is given in this book to explain Self Reference.
    REPORT  z_self_reference.
    *       CLASS client DEFINITION
    CLASS client DEFINITION.
      PUBLIC SECTION.
        DATA name(10) TYPE c VALUE 'Master' READ-ONLY.
        METHODS create_server.
    ENDCLASS.                    "client DEFINITION
    *       CLASS server DEFINITION
    CLASS server DEFINITION.
      PUBLIC SECTION.
        METHODS acknowledge
         IMPORTING creator TYPE REF TO client.
      PRIVATE SECTION.
        DATA name(10) TYPE c VALUE 'Servant'.
    ENDCLASS.                    "server DEFINITION
    *       CLASS client IMPLEMENTATION
    CLASS client IMPLEMENTATION.
      METHOD create_server.
        DATA server_ref TYPE REF TO server.
        CREATE OBJECT server_ref.
        CALL METHOD server_ref->acknowledge
          EXPORTING
            creator = me.
      ENDMETHOD.                    "create_server
    ENDCLASS.                    "client IMPLEMENTATION
    *       CLASS server IMPLEMENTATION
    CLASS server IMPLEMENTATION.
      METHOD acknowledge.
        DATA name TYPE string.
        name = creator->name.
        WRITE: me->name, 'create by', name.
      ENDMETHOD.                    "acknowledge
    ENDCLASS.                    "server IMPLEMENTATION
    DATA client_ref TYPE REF TO client.
    START-OF-SELECTION.
      CREATE OBJECT client_ref.
      CALL METHOD client_ref->create_server.
    Thanks,
    Mohit Goel.
    Edited by: Matt on Apr 8, 2009 10:50 AM

    Hi Mohit,
    me is used to self reference the attributes and methods of a class within that class.In your program,
    within client class implementation, you can use me->name and me->create_server to call the name variable and create_server method in the same class if required.Here me represents "client class".Similarly ,in Server class, you can use me->name and me->acknowledge to call the name variable and acknowledge method in the same class if required.
    In your program ,
    CALL METHOD server_ref->acknowledge
    EXPORTING
    creator = me.  
    is not correct.me is not used as variable . Its only a reference variable.it shoud used me->class attribute(name)/method.
    I hope , you could understand the above explanation.
    by
    Prasad GVK.

  • Create two one-to-one self-reference mappings

    We need help on the following problem with Toplink:
    We have a table massnahme with several attributes.
    table massnahme
    massnahmeID
    prevMassnahme
    nextMassnahme
    prevMassnahme, nextMassnahme are self-references on massnahme. We take prevMassnahme and nextMassnahme as a one-to-one mapping to massnahme. The target reference on prevMassnahme and nextMassnahme is massnahmeID.
    If we create a new Object massnahme_B and set prevMassnahme on this massnahme_B to an existing massnahme_A and set the nextMassnahme on the existing massnahme_A to the new massnahme_B, then it seems that toplink tries to make the update on the existing massnahme_A before the insert of the new massnahme_B. That causes an exception, because toplink tries to insert an empty massnahme into the database.
    Any help on this topic would be appreciated.
    The Toplink Mapping Workbench we use has the version 9.0.4.2.
    Thomas

    Here the Java-Code and Descriptor Snippets, where Anamnese and Aufnahmevorgang are both derived classes of Massnahme and cloneAufnahmevorgang is registered earlier in the code (same UnitOfWork).
    <mapping>
    <inherited>false</inherited>
    <instance-variable-name>prevMassnahme</instance-variable-name>
    <uses-method-accessing>false</uses-method-accessing>
    <read-only>false</read-only>
    <get-method-handle>
    <method-handle empty-aggregate="true"/>
    </get-method-handle>
    <set-method-handle>
    <method-handle empty-aggregate="true"/>
    </set-method-handle>
    <reference-descriptor>de.kvwl.masc.se.model.Massnahme.ClassDescriptor</reference-descriptor>
    <private-owned>false</private-owned>
    <uses-batch-reading>false</uses-batch-reading>
    <table-reference-mapping-reference-handle>
    <reference-handle>
    <reference-table>MASSNAHME</reference-table>
    <reference-name>MASSNAHME_C05</reference-name>
    </reference-handle>
    </table-reference-mapping-reference-handle>
    <uses-joining>false</uses-joining>
    <one-to-one-mapping-indirection-policy>
    <indirection-policy>
    <uses-indirection>true</uses-indirection>
    </indirection-policy>
    </one-to-one-mapping-indirection-policy>
    <mapping-class>MWOneToOneMapping</mapping-class>
    </mapping>
    <mapping>
    <inherited>false</inherited>
    <instance-variable-name>nextMassnahme</instance-variable-name>
    <uses-method-accessing>false</uses-method-accessing>
    <read-only>false</read-only>
    <get-method-handle>
    <method-handle empty-aggregate="true"/>
    </get-method-handle>
    <set-method-handle>
    <method-handle empty-aggregate="true"/>
    </set-method-handle>
    <reference-descriptor>de.kvwl.masc.se.model.Massnahme.ClassDescriptor</reference-descriptor>
    <private-owned>false</private-owned>
    <uses-batch-reading>false</uses-batch-reading>
    <table-reference-mapping-reference-handle>
    <reference-handle>
    <reference-table>MASSNAHME</reference-table>
    <reference-name>MASSNAHME_C07</reference-name>
    </reference-handle>
    </table-reference-mapping-reference-handle>
    <uses-joining>false</uses-joining>
    <one-to-one-mapping-indirection-policy>
    <indirection-policy>
    <uses-indirection>true</uses-indirection>
    </indirection-policy>
    </one-to-one-mapping-indirection-policy>
    <mapping-class>MWOneToOneMapping</mapping-class>
    </mapping>
    Anamnese cloneAnamnese = (Anamnese) getUow().registerExistingObject(anamnese);
    cloneAufnahmevorgang.setPrevMassnahme(cloneAnamnese);
    cloneAnamnese.setNextMassnahme(cloneAufnahmevorgang);
    getUow().commit();
    Any further Information needed?
    Thomas

  • Self Reference Model Class - How to populate using Entity Framework

    Hi,i have table in SQL Server named Employees as follows:
    EmployeeId lastName FirstName reportsTo
    1 Davolio Nancy 2
    2 Fuller Andrew NULL
    3 Leverling Janet 2
    4 Peacock Margaret 2
    5 Buchanan Steven 2
    6 Suyama Michael 5
    7 King Robert 5
    8 Callahan Laura 2
    9 Dodsworth Anne 5
    I would like to use Entity Framework to populate my Model Class .My model class looks as follows:
    public class Employees
        readonly List<Employees> _children = new List<Employees>();
        public IList<Employees> Children
            get { return _children; }
        public string FirstName { get; set; }
        public string LastName {get; set;}
    I want to use this class in ViewModel  to populate my TreeView control. Can anyone help me in order to define Linq to Entities in order to populate my model class Employees from table in SQL Server as defined. Thanks in advance.
    Almir

    Hello Fred,
    unfortunately it does not work, maybe I can be more specific about what I'm trying to get. I'm following Josh Smith's article on CodeProject related to WFP TreeView
    Josh Smith article. He has Class named Person with the following structure
    public class Person
    readonly List<Person> _children = new List<Person>();
    public List<Person> Children
    get
    return _children;
    public string Name { get; set; }
    The same is populated from Database class using method named GetFamilyTree() which look as follows:
    public static Person GetFamilyTree()
    // In a real app this method would access a database.
    return new Person
    Name = "David Weatherbeam",
    Children =
    new Person
    Name="Alberto Weatherbeam",
    Children=
    new Person
    Name="Zena Hairmonger",
    Children=
    new Person
    Name="Sarah Applifunk",
    new Person
    Name="Jenny van Machoqueen",
    Children=
    new Person
    Name="Nick van Machoqueen",
    new Person
    Name="Matilda Porcupinicus",
    new Person
    Name="Bronco van Machoqueen",
    new Person
    Name="Komrade Winkleford",
    Children=
    new Person
    Name="Maurice Winkleford",
    Children=
    new Person
    Name="Divinity W. Llamafoot",
    new Person
    Name="Komrade Winkleford, Jr.",
    Children=
    new Person
    Name="Saratoga Z. Crankentoe",
    new Person
    Name="Excaliber Winkleford",
    I'm trying to figure out how should I write
    GetFamilyTree() method using Entity Framework in order to connect to my SQL Server database and populate this Person class as it was populated manually in Joshs Example. The table I'm using in SQL Server is described in
    my first post named Employees (it's self reference table)

  • Self reference This  in java

    Hi all
    Does any one know, how the self reference variable "this" works. That is how and when "this" variable is instantiated.
    How value of "this" keeps on changing???
    Is "This" static, final, private??
    Any help will be appreciated.
    regards
    prince.k

    Well lets assume it is a keyword. What i want to know
    is how it is made to refer to the current object. I
    guess the compiler adds some code for "this", so what
    is that code??What makes you think the compiler adds code? Do you mean Java code?
    U said it isn't static; No I didn't. I said that if you insist on thinking about it as a variable, then consider it non-static.
    but it is static as u can
    access it from ur class by saying "classname.this".That is just a syntax. As this is not a variable, classname.this does not imply it is static. There is one value per instance of any class (namely, the value for any given instance is a reference to that instance). If it were static, there would be one value shared by all instances of the class. Either way, this is a moot point.
    But had it been final, it should be able to to refer
    to only one object.It does. The current object.
    but it keeps on changing....as it refer to the object
    which called a particuler method of that class.No it doesn't - can you give an example of what you believe is the value of this changing?

  • Data Modeler: How to create a self reference in ER?

    e.g. I create the entity EMP in a logical Subview. Two attributes are here essential for a self-reference: EMPNO and MGR. So each Employee has a reference to his boss. And this information is stored in MGR.
    Now I create the entity EMP with the 8 columns from the SCOTT/TIGER schema. After that I define a 1:N-Relation between EMP and EMP. but it looks like I cannot define, which attributes are starting point of the relation and destination.
    Who can help me here?
    Gerd

    Gerd,
    you cannot select destination (as you said) attribute - they are automatically generated. However you can achieve what you want - it depends on your starting point:
    1) start from logical model (analysis first)
    - you create 1:n recursive relationship -
    - change the name of created FK attribute to MGR or what ever you want - this is controlled by "FK Attribute name synchronization" setting at "General options>Model>Logical" page
    2) start from relational model (reverse engineering of existing status)
    - create self reference foreign key - select MGR as FK column;
    - reverse engineer to logical model - you'll have FK attribute named MGR
    Philip

  • Recursive Self Reference

    Hi,
    I am trying to do a recursive self reference. Is this the best way of doing it as I keep getting errors?
    SQL> CREATE OR REPLACE TYPE type_objtyp AS OBJECT (
    2 type_id NUMBER (10),
    3 type_name VARCHAR2 (100),
    4 sub_type REF type_objtyp
    5 )
    6 NOT FINAL
    7 /
    Type created.
    SQL> CREATE OR REPLACE TYPE data_objtyp
    2 /
    Type created.
    SQL> CREATE OR REPLACE TYPE data_list_objtyp AS TABLE OF data_objtyp
    2 /
    Warning: Type created with compilation errors.
    SQL> CREATE OR REPLACE TYPE data_objtyp AS OBJECT (
    2 data_id NUMBER (10),
    3 type_ref REF type_objtyp,
    4 creation_date DATE,
    5 child_list_ref REF data_list_objtyp
    6 )
    7 NOT FINAL
    8 /
    Warning: Type created with compilation errors.
    SQL>
    SQL> COMMIT
    2 /
    Commit complete.
    SQL> show errors
    Errors for TYPE DATA_OBJTYP:
    LINE/COL ERROR
    0/0 PL/SQL: Compilation unit analysis terminated
    5/25 PLS-00532: Target of REF must be a complete or incomplete object
    type.

    you can't have a REF to a table type, only to object types. so, instead use a table of REFs:
    -- incomplete declaration
    create or replace type data_objtyp;
    -- declare table type
    create or replace type data_objtyp_list is table of REF data_objtyp;
    -- complete data object declaration
    create or replace type data_objtyp is object (
    data_id NUMBER (10),
    type_ref REF type_objtyp,
    creation_date DATE,
    child_list data_objtyp_list
    NOT FINAL;
    hope that helps... g

  • Reg Self Service Personalization for Termination transaction

    Hi All,
    I am new to self service personalization. User wants to personalize the self servie pages.
    User Requirement: our client has diffetent self service transactions like
    Payroll Name and Subgroup Change
    Termination
    Location Only Changes
    People Group Only Changes etc.
    Whenever user is selecting Termination as transaction, and continued to the next step, calendar shows up to select the date for termination. Here I need to personalize such that user should select last day of the employee as termination date rather than following day.
    Eg: Employee last date is 01-oct-2009, prersently some users are taking 02-oct-2009 as termination date assuming that 01-oct-2009 is the last working day. For payroll process, 01-oct-2009 needs to be last day of the employee and he needs to terminate same date for processing.
    Please advise me.

    You can't do this through personalization. You need to extend the page controller to restrict it.
    Thanks
    --Anil                                                                                                                                                                                                                                       

  • Passing self reference to a method call.

    I have classes 'A' & 'B'.
    A's method 'M1' calls a B's method 'M2'which takes object of type 'A' as an argument.
    Is it possible to use 'this' keyword or do I need to use Class.forName('A')
    If not, is there a better way to accomplish the same.
    Ex:
    public class A
    public M1()
    //calls a method M2 on B that takes object of type 'A' as argument
    B b = new B().M2(this);
    }//end of class
    public class B
    public Object M2(A a)
    }//end of class B
    Thanks in advance.

    Class.forName("A") returns an object of type Class, not an object of type A. So it won't work. this would work.

  • Issue with self reference on ManyToOne relationship

    Hi,
    I have a scenario where one of the columns on a table refers to the ID of the same table for a @ManyToOne relationship. Here is an example class below to better explain the situation:
    @Entity
    @Table(name = "DEPARTMENT")
    public class Department implements java.io.Serializable
    @Id
    private int ID;
    @ManyToOne(targetEntity = Department.class, fetch = FetchType.EAGER)
    @JoinColumn(name = "PARENT_ID")
    private Department parent;
    @OneToMany(mappedBy = "parent", targetEntity = Department.class, fetch = FetchType.LAZY)
    private Set<Category> children = new HashSet<Category>(0);
    Here if you notice the parent is the ID of another Department. When I use this during a create it seems to be trying to update the ID of an existing Department record, which is causing an exception as follows:
    SEVERE: Error processing request from 127.0.0.1 for <anon>: javax.persistence.RollbackException: Exception [TOPLINK-7251] (Oracle TopLink Essentials - 2.0 (Build b41d-beta2 (04/24/2007))): oracle.toplink.essentials.exceptions.ValidationException
    Exception Description: The attribute [ID] of class [Department] is mapped to a primary key column in the database. Updates are not allowed.
    Any thoughts on what I might be doing wrong. Appreciate your help.
    Thanks,
    Sharanya

    Thanks for the help.
    It turns out the problem was related to executing a SELECT query on the entities prior to committing the transaction. Essentially, there were entities which were being created and persisted (but not committed), and these records were being retrieved via a SELECT query. At the point the query was executed, an attempt was made to flush, and since the record hadn’t been updated in the persistence context, TopLink saw the SELECT query execution as an update and thus threw the exception.
    /* simplified for brevity */
    @Entity
    class Record {
        @Id
        @GeneratedValue(…)
        private Integer id;
        @ManyToOne(…)
        private Record parent;
        @OneToMany(…)
        private Collection<Record> children;
    class RecordService {
        void addRecords(Record records…) {
            for (Record record : records) {
                addRecord(record);
        void addRecord(Record record) {
            // Execute a SELECT to get related record(s).
            // Update the record(s).
            em.persist(record);
    To resolve this, I simply persist the records before executing the SELECT query, and then after the records are updated, execute a merge:
        void addRecord(Record record) {
            em.persist(record);
            // Execute a SELECT query to get related record(s).
            // Update the record(s).
            em.merge(record);
    I'm not completely clear as to what point TopLink thought that the ID had been updated (it could be related to the previous post?), but this resolution seems to be working.

  • Self reference to the table issue-Query required

    Hi,
    I have the below query which will give me the result as
    select DC.Fullname as Fullname, DSL.Skills as Skills, AdminSC.SkillRatingID as Rating
                        from dim_Contacts DC
                        inner join admin_skills AdminSC on DC.attid = AdminSC.attid
                        inner join dim_Skill DSL on DSL.ID = AdminSC.skillID
                        inner join dim_Pattern DPS on DPS.SkillID = DSL.ID
                        where DPS.PatternTypeID = '2'
    Fullname
    Skills
    Rating
    Rahul
    BO Universe
    2
    Kiran
    Crystal Reports / Webi
    4
    Now what I am looking for is,I need to get 2 more rows with null values(eg :Rahul-Crystal Reports/Webi-0).Please find the required result set.
    Fullname
    Skills
    Rating
    Rahul
    BO Universe
    2
    Kiran
    Crystal Reports / Webi
    4
    Rahul
    Crystal Reports / Webi
    0
    Kiran
    BO Universe
    0
    Please help me in providing the query.Thanks

    You can use LEFT OUTER JOIN with Skills Table like follow query:
    SELECT DC.Fullname AS Fullname ,
    DSL.Skills AS Skills ,
    AdminSC.SkillRatingID AS Rating
    FROM dim_Contacts DC
    INNER JOIN admin_skills AdminSC ON DC.attid = AdminSC.attid
    LEFT OUTER JOIN dim_Skill DSL ON DSL.ID = AdminSC.skillID
    INNER JOIN dim_Pattern DPS ON DPS.SkillID = DSL.ID
    WHERE DPS.PatternTypeID = '2'
    sqldevelop.wordpress.com

  • Java.lang.IllegalArgumentException: References to entities are not allowed

    Hi,
    I am using Berkely DB(native edition) 5.0.21 version. I have a couple classes as defined below:
    Class - 1:
    package bdb.test;
    import java.util.List;
    import com.sleepycat.persist.model.Entity;
    import com.sleepycat.persist.model.PrimaryKey;
    @Entity
    public class Employee {
         @PrimaryKey
         private String id ;
         private String name;
         private List<Employee> reportingManagers ;
         public String getId() {
              return id;
         public void setId(String id) {
              this.id = id;
         public String getName() {
              return name;
         public void setName(String name) {
              this.name = name;
         public List<Employee> getReportingManagers() {
              return reportingManagers;
         public void setReportingManagers(List<Employee> managers) {
              this.reportingManagers = managers;
    Class - 2 :
    package bdb.test;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.util.ArrayList;
    import java.util.List;
    import com.sleepycat.db.DatabaseException;
    import com.sleepycat.db.Environment;
    import com.sleepycat.db.EnvironmentConfig;
    import com.sleepycat.persist.EntityStore;
    import com.sleepycat.persist.PrimaryIndex;
    import com.sleepycat.persist.StoreConfig;
         public class BDBTest{
              public static void main(String agrs[]){
                   Environment myEnv;
                   EntityStore store;
                   try {
                        EnvironmentConfig myEnvConfig = new EnvironmentConfig();
                        myEnvConfig.setCacheSize(30000);
                        StoreConfig storeConfig = new StoreConfig();
                        myEnvConfig.setAllowCreate(true);
                        myEnvConfig.setInitializeCache(true);
                        storeConfig.setAllowCreate(true);
                        try {
                        // Open the environment and entity store
                        myEnv = new Environment(new File("c:\\BDBTEST\\"), myEnvConfig);
                        store = new EntityStore(myEnv, "MyStore", storeConfig);
                        PrimaryIndex<String, Employee> primaryIndex = store.getPrimaryIndex(String.class, Employee.class);
                        // write Employee
                        Employee employee = buildEmployee("E1", "EMP1");
                        primaryIndex.putNoReturn(employee);
                   } catch (FileNotFoundException fnfe) {
                        System.err.println(fnfe.toString());
                        System.exit(-1);
                   } catch(DatabaseException dbe) {
                        System.err.println("Error opening environment and store: " +
                        dbe.toString());
                        System.exit(-1);
              public static Employee buildEmployee(String id,String name){
                   Employee employee = new Employee();
                   employee.setId(id);
                   employee.setName(name);
                   employee.setManagers(buildManager());
                   return employee;
              public static List<Employee> buildManager(){
                   List <Employee> managers = new ArrayList<Employee>();
                   Employee manager1 = new Employee();
                   manager1.setId("M111");
                   manager1.setName("Manager1");
                   Employee manager2 = new Employee();
                   manager2.setId("M222");
                   manager2.setName("Manager2");
                   managers.add(manager2);
                   return managers;
    While running the Class 2, I am getting the following exception :
    Exception in thread "main" java.lang.IllegalArgumentException: References to entities are not allowed: bdb.test.Employee
         at com.sleepycat.persist.impl.RecordOutput.writeObject(RecordOutput.java:94)
         at com.sleepycat.persist.impl.ObjectArrayFormat.writeObject(ObjectArrayFormat.java:137)
         at com.sleepycat.persist.impl.RecordOutput.writeObject(RecordOutput.java:114)
         at com.sleepycat.persist.impl.ReflectionAccessor$ObjectAccess.write(ReflectionAccessor.java:398)
         at com.sleepycat.persist.impl.ReflectionAccessor.writeNonKeyFields(ReflectionAccessor.java:258)
         at com.sleepycat.persist.impl.ReflectionAccessor.writeNonKeyFields(ReflectionAccessor.java:255)
         at com.sleepycat.persist.impl.ComplexFormat.writeObject(ComplexFormat.java:528)
         at com.sleepycat.persist.impl.ProxiedFormat.writeObject(ProxiedFormat.java:116)
         at com.sleepycat.persist.impl.RecordOutput.writeObject(RecordOutput.java:114)
         at com.sleepycat.persist.impl.ReflectionAccessor$ObjectAccess.write(ReflectionAccessor.java:398)
         at com.sleepycat.persist.impl.ReflectionAccessor.writeNonKeyFields(ReflectionAccessor.java:258)
         at com.sleepycat.persist.impl.ComplexFormat.writeObject(ComplexFormat.java:528)
         at com.sleepycat.persist.impl.PersistEntityBinding.writeEntity(PersistEntityBinding.java:103)
         at com.sleepycat.persist.impl.PersistEntityBinding.objectToData(PersistEntityBinding.java:83)
         at com.sleepycat.persist.PrimaryIndex.putNoOverwrite(PrimaryIndex.java:474)
         at com.sleepycat.persist.PrimaryIndex.putNoOverwrite(PrimaryIndex.java:449)
         at bdb.test.BDBTest.main(BDBTest.java:42)
    Question : In the above example reportingManagers is also a list of Employee classes. Can't I self reference a object with in the same object ? How do I store list of reportingManagers in this example? Any help is highly appreciated.
    Thanks,
    Bibhu

    Hi Sandra,
    Thanks for the reply.
    Is there any restrictions in Berkeley DB to store cyclic referencing objects?
    API documentation for Entity annotation talks about cyclic references in one of section but contradicts the same in another section. Please refer the link below:
    [ http://download.oracle.com/docs/cd/E17076_02/html/java/com/sleepycat/persist/model/Entity.html]
    Following sections of this documentation contradicts each other. I have highlighted both of them in bold.
    Other Type Restrictions:
    Entity classes and subclasses may not be used in field declarations for persistent types. Fields of entity classes and subclasses must be simple types or non-entity persistent types (annotated with Persistent not with Entity).
    If a field of an Entity needs to reference an object, the referenced object should be marked with @Persistent and not with @Entity. So, self referencing is not possible as the main class would have been marked with @Entity.
    Embedded Objects
    As stated above, the embedded (or member) non-transient non-static fields of an entity class are themselves persistent and are stored along with their parent entity object. This allows embedded objects to be stored in an entity to an arbitrary depth.
    There is no arbitrary limit to the nesting depth of embedded objects within an entity; however, there is a practical limit. When an entity is marshalled, each level of nesting is implemented internally via recursive method calls. If the nesting depth is large enough, a StackOverflowError can occur. In practice, this has been observed with a nesting depth of 12,000, using the default Java stack size. This restriction on the nesting depth of embedded objects does not apply to cyclic references, since these are handled specially as described below.
    Self referencing is possible.
    Object Graphs
    When an entity instance is stored, the graph of objects referenced via its fields is stored and retrieved as a graph. In other words, if a single instance is referenced by two or more fields when the entity is stored, the same will be true when the entity is retrieved. When a reference to a particular object is stored as a member field inside that object or one of its embedded objects, this is called a cyclic reference. Because multiple references to a single object are stored as such, cycles are also represented correctly and do not cause infinite recursion or infinite processing loops. If an entity containing a cyclic reference is stored, the cyclic reference will be present when the entity is retrieved.
    My question:
    In the above first highlighted section says to store a referenced/embedded object it needs be marked with @Persistent and not with @Entity annotation. That rules out storage of cyclic referencing object since the main object would have been already marked with @Entity annotation. The second section indicates having support for cyclic references.
    So, Is it possible to store cyclic referencing objects in BDB? if yes, how it should be done?
    Thanks,
    Bibhu
    Edited by: user12848956 on Jan 20, 2011 7:19 AM

  • Self referencing alias of shared drive

    My Issue:
    I'm using an iMac with freshly installed OS X Mavericks.
    I can't access a shared drive from a remote MacMini anymore.
    When I click on the drive, I get a self reference and thus an infinite
    loop to that drive.
    How I got there:
    Like before in Mountain Lion, I tried to drag the shared drive into the Favorites side bar in Finder,
    but that didn't work anymore (for whatever reason) in Mavericks.
    I did some research and got the hint, to drag the shared drive into the ~/Library/Favorites folder.
    This didn't work either, so I deleted that alias from the Favorites folder again, but since then I have
    the above behaviour.
    How can I delete this self-reference alias? Where is the alias-information stored?
    Thanks for your help
    Thomas

    Problem is solved. Rebooting of both computers removed the circular reference,
    however, my initial problem still exists:
    I can't drag the shared remote drive to Favorites in Finder anymore.
    This has worked in Mountain Lion and before, but not anymore in Mavericks.
    any idea?

Maybe you are looking for