-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: retrieve data and write it to a hashtable
PostPosted: Fri Feb 01, 2008 1:37 pm 
Beginner
Beginner

Joined: Tue Jan 22, 2008 11:33 am
Posts: 46
I would like to retrieve data form a table and write Values to a hashtable


Code:
public class MyClass
{
static Hashtable myHash;

static MyClass()
{
Configuration cfg = new Configuration();
            cfg.AddAssembly("...");
            ISessionFactory factory = cfg.BuildSessionFactory();
            ISession session = factory.OpenSession();
            ITransaction transaction = session.BeginTransaction();
           
            IList results = session.CreateCriteria(typeof(ProductType)).List();

foreach (ProductType myProduct in results)
            {   
myHash.Add(myProduct.TypeName,  myProduct.TypeId);
            }
}
}


the List() Method retrieves all data. But it comes to myHash.Add it always throws an exception "Creating a proxy instance failed". The debugger jumps to code which caused to constructor call of MyClass.


Any idea how I can retrieve all rows of a table and write the name and id column (both are strings) of each row to a hashtable or Enum?

Thanks antoschka


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 01, 2008 3:26 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
I would assume that anything dealing with persistable classes has to live on a class instance. Try using a non-static HashTable.

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 01, 2008 3:53 pm 
Beginner
Beginner

Joined: Fri Aug 10, 2007 3:34 am
Posts: 44
you could also try to make a hashtable collection to your class and map it
then you would trully persist the data to a hashtable
(what you did there is just filling a hashtable...)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 01, 2008 5:03 pm 
Beginner
Beginner

Joined: Tue Jan 22, 2008 11:33 am
Posts: 46
Sounds good, but how exactly can I do that?

Thanks in advance

antoschka


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 02, 2008 1:19 am 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
I your collection of children is anything but a Set, you can still persist it, but through the interface UserCollectionType.

_________________
Gonzalo Díaz


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.