[omniORB] Persistent object is not persistent

yashik@veon.com yashik@veon.com
Wed, 1 May 2002 19:23:39 +0200


Hello,

I'm trying to create a persistent object just like as it said in "Advanced
CORBA programming" book:

1. Create  PERSISTENT LifespanPolicy object
2. Create a USER_ID id_assignment policy object
3. Create a new POA with the above policies
4. Create object id and instantiating the servant
5. Activate the object and get object reference by  object id
The program converts that object to string prints the string and exit.

Why I'm getting different IORs every time? What I'm missing?
Any help will be greatly appritiated.

Yakov.



Here is the code:

    PortableServer::POAManager_var pman = root_poa->the_POAManager();
    pman->activate();

    // Create a PERSISTENT LifespanPolicy object
   PortableServer::LifespanPolicy_var lifespan =
root_poa->create_lifespan_policy(PortableServer::PERSISTENT);;
   // Create a USER_ID id_assignment policy object
   PortableServer::IdAssignmentPolicy_var idassignment =
root_poa->create_id_assignment_policy(PortableServer::USER_ID);

    // Create a new POA with the persistent lifespan policy.
    CORBA::PolicyList pl;
    pl.length(2);
    pl[0] = lifespan;
    pl[1] = idassignment;
    PortableServer::POA_var poa = root_poa->create_POA("My POA", pman, pl);

    // Create object id (Always use the same one)
    PortableServer::ObjectId_var oid =
          PortableServer::string_to_ObjectId("My Object");

   // Create the servant
   MyServant_impl* servant = new MyServant();

  // Activate the object
  poa->activate_object_with_id(oid, servant);

  // Destroy policy objects
 lifespan->destroy();
 idassignment->destroy();

    //obj = servant->_this();
  obj = poa->id_to_reference(oid);

    CORBA::String_var sior(orb->object_to_string(obj));
     std::cerr << (char*)sior << std::endl;