Go Back   ZeroC Forums > Help Center

Reply
 
LinkBack Thread Tools Rate Thread Display Modes
  #1 (permalink)  
Old 07-09-2005
MKoleoso MKoleoso is offline
Registered User
 
 
Join Date: Feb 2004
Location: Aachen, Germany
Posts: 9
Problem: Reading back persistent maps

Hi there!

Q: I'm currently unsuccessfully attempting to read back some persistent values i've stored. Please advise
me on what i'm missing. I get an exception (Microsoft C++ exception: Ice::NoObjectFactoryException @ 0x0012eea8).

I have a map:
StringPersistentUserAccountMap userAccountsMap(dbConnection, "UserAccounts");

filled with entries (4):
...
std::string newName3= "User3";
WGICE::PersistentUserAccountPtr newValue3= new WGICE::PersistentUserAccountI();
newValue1->Set("User3","Pass3","User3@UserGroup.com");
userAccountsMap.insert(make_pair(newName3,newValue 3));
...

and an object factory:
class ObjectFactory : public Ice::ObjectFactory
{
public:
virtual Ice::ObjectPtr create(const std::string & type)
{
if(type == "::WGICE::PersistentUserAccount");
return new ::WGICE::PersistentUserAccountI();

assert(false);
}
...
};

and setup the object factory:
ic = Ice::initialize(argc, argv);
ic->addObjectFactory(new ObjectFactory,"::WGICE::PersistentUserAccount");


I fail to get back any of the values:
StringPersistentUserAccountMap::iterator iterator;
for (iterator= userAccountsMap.begin();iterator!= userAccountsMap.end();iterator++)
{
...
std::string value= iterator->first;
...
}

with the following exception (NoObjectFactory):
Eine Ausnahme (erste Chance) bei 0x7c81eb33 in LoginTestServer.exe:
Microsoft C++ exception: Ice::NoObjectFactoryException @ 0x0012eea8.

Regards.
Reply With Quote
  #2 (permalink)  
Old 07-09-2005
matthew's Avatar
matthew matthew is online now
ZeroC Staff
 
Name: Matthew Newhook
Organization: ZeroC, Inc.
Project: Internet Communications Engine
 
Join Date: Feb 2003
Location: NL, Canada
Posts: 1,060
The sample code looks correct. If you post a complete self-contained example that demonstrates the problem we'll look into it. Alternatively, if you a debug version of Ice available you could put a breakpoint in

ObjectFactoryPtr
IceInternal::ObjectFactoryManager::find(const string& id) const

and see what type Ice is trying to demarshal when reading from the database. You could also dump the contents of the database with dbdump to findout what is actually in there (see the manual for more information on this tool).

Regards, Matthew
Reply With Quote
  #3 (permalink)  
Old 07-10-2005
MKoleoso MKoleoso is offline
Registered User
 
 
Join Date: Feb 2004
Location: Aachen, Germany
Posts: 9
Database is not correct, wrong writing code?

Hi again,
while dumping the database, I noticed that 3 of the 4 entries are not valid. Do I need some kind of commit or so after each new data entry?

Command:
C:\Projects>dumpdb --key string --value ::WGICE::PersistentUserAccount --load C:\Projects\Wiederganger\projects_windows\Interfac es\PersistentUserAccount.ice .\data\userdata_db UserAccounts

DB Content:
Key: 'User1'
Value: class ::WGICE::PersistentUserAccount (object #0)
{
mName = 'User1'
mPassword = 'Pass1'
mEmail = 'User1@UserGroup.com'
}
Key: 'User2'
Value: class ::WGICE::PersistentUserAccount (object #0)
{
mName = ''
mPassword = ''
mEmail = ''
}
Key: 'User3'
Value: class ::WGICE::PersistentUserAccount (object #0)
{
mName = ''
mPassword = ''
mEmail = ''
}
Key: 'User4'
Value: class ::WGICE::PersistentUserAccount (object #0)
{
mName = ''
mPassword = ''
mEmail = ''
}

This was the initial code used to create the entries:
#ifdef MAKE_USER_ACCOUNTS
userAccountsMap.clear();

std::string newName1= "User1";
WGICE::PersistentUserAccountPtr newValue1= new WGICE::PersistentUserAccountI();
newValue1->Set("User1","Pass1","User1@UserGroup.com");
userAccountsMap.insert(make_pair(newName1,newValue 1));

std::string newName2= "User2";
WGICE::PersistentUserAccountPtr newValue2= new WGICE::PersistentUserAccountI();
newValue1->Set("User2","Pass2","User2@UserGroup.com");
userAccountsMap.insert(make_pair(newName2,newValue 2));

std::string newName3= "User3";
WGICE::PersistentUserAccountPtr newValue3= new WGICE::PersistentUserAccountI();
newValue1->Set("User3","Pass3","User3@UserGroup.com");
userAccountsMap.insert(make_pair(newName3,newValue 3));

std::string newName4= "User4";
WGICE::PersistentUserAccountPtr newValue4= new WGICE::PersistentUserAccountI();
newValue1->Set("User4","Pass4","User4@UserGroup.com");
userAccountsMap.insert(make_pair(newName4,newValue 4));
#endif

Thanks again.
Reply With Quote
  #4 (permalink)  
Old 07-11-2005
benoit's Avatar
benoit benoit is offline
ZeroC Staff
 
Name: Benoit Foucher
Organization: ZeroC, Inc.
Project: Ice
 
Join Date: Feb 2003
Location: Rennes, France
Posts: 1,540
Your code to fill the records is suspicious, you always call "Set" on "newValue1":

Code:
newValue1->Set("User2","Pass2","User2@UserGroup.com");
newValue1->Set("User3","Pass3","User3@UserGroup.com");
newValue1->Set("User4","Pass4","User4@UserGroup.com");
I assume you should be calling Set on newValue2, newValue3, newValue4 here instead?

Note that you should also make sure that you register the object factory with the communicator before to create the map.

Benoit.
Reply With Quote
  #5 (permalink)  
Old 07-11-2005
bernard's Avatar
bernard bernard is online now
ZeroC Staff
 
Name: Bernard Normier
Organization: ZeroC, Inc.
Project: Ice
 
Join Date: Feb 2003
Location: Palm Beach Gardens, FL
Posts: 816
Just two clarifications:

- You need to register class factories before you open a Freeze dictionary (or Evictor) only if you use one or more index, because Freeze/Berkeley DB populates empty indices during opening (and therefore needs to create class objects). In general it's a good idea to always do so, since you may add indices later on.

- Freeze uses transactions for all write operations. If you don't create a transaction (with connection->beginTransaction()), every single Map write operation (insert, erase, put) is enclosed in its own transaction, so you don't need to worry about committing anything; if you use an iterator for your write operations (for example to erase some entries), then Freeze associates an internal transaction with this iterator and this transaction is committed when the iterator is closed (see the Freeze chapter in the Ice book for details on when Freeze closes iterators).

Cheers,
Bernard
Reply With Quote
  #6 (permalink)  
Old 07-12-2005
MKoleoso MKoleoso is offline
Registered User
 
 
Join Date: Feb 2004
Location: Aachen, Germany
Posts: 9
Update: DB is OK, Read is bad

Hello again,
the DB was broken due to the error in assigning values as benoit writes. However, after recreating th DB correctly, accessing the "User3" value gives me a "non rtti object" error as shown below (error occurs in the line with the find code). Before the error occurs, the object factory is called correctly with the right type.

error:
(handle.h) Unbehandelte Ausnahme bei 0x7c81eb33 in LoginTestServer.exe: Microsoft C++ exception: __non_rtti_object @ 0x0012edd4.

code:
StringPersistentUserAccountMap::const_iterator value= userAccountsMap.find("User3");
const std::string name= value->first;

DB data dump:
Key: 'User3'
Value: class ::WGICE::PersistentUserAccount (object #0)
{
mName = 'User3'
mPassword = 'Pass3'
mEmail = 'User3@UserGroup.com'
}


I would líke to chew on this problem a bit before I submit a complete sample,but i'm open for tips. I need to understand ICE better.

Thanks!
Reply With Quote
  #7 (permalink)  
Old 07-12-2005
MKoleoso MKoleoso is offline
Registered User
 
 
Join Date: Feb 2004
Location: Aachen, Germany
Posts: 9
Update: Error is in line where first is accessed

FYI,
the error occurs in the line
const std::string name= value->first;

not in the find(...).
Reply With Quote
  #8 (permalink)  
Old 07-12-2005
benoit's Avatar
benoit benoit is offline
ZeroC Staff
 
Name: Benoit Foucher
Organization: ZeroC, Inc.
Project: Ice
 
Join Date: Feb 2003
Location: Rennes, France
Posts: 1,540
Hi,

Did you compile your code with /GR? See this link for an explanation of the "__non_rtti_object" exception.

Benoit.
Reply With Quote
  #9 (permalink)  
Old 07-12-2005
MKoleoso MKoleoso is offline
Registered User
 
 
Join Date: Feb 2004
Location: Aachen, Germany
Posts: 9
Smile Solved! /GR settings on the project level

Setting /GR on the Visual Studio project level instead of for each file solved the problem for me.

Thank you!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
What is best way to transfer files back and forth alexm Help Center 2 04-03-2006 05:57 PM
Slice bool always maps to True in python server sac_urs Bug Reports 3 11-17-2005 07:35 AM
is the context sent back to the client?? DeepDiver Help Center 2 05-25-2005 10:55 AM
IceStorm: Persistent messages stephan Help Center 1 09-15-2004 10:11 PM
Persistent messaging service stephan Comments 7 06-14-2004 12:27 PM


All times are GMT -4. The time now is 10:55 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0
(c) 2008 ZeroC, Inc.