-->
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.  [ 9 posts ] 
Author Message
 Post subject: SessionFactory
PostPosted: Sun Dec 14, 2003 12:24 am 
Newbie

Joined: Tue Sep 16, 2003 4:45 pm
Posts: 14
Hi There,

I have a following code, segment that queries a the database.The database i am using is Mysql 4.0 and Jboss as the application server.
After few consecutive queries. I start getting mysql state exceptions saying the access to database is denied.
I dont have the dump of the exceptions. Could i get any help on what the problem might me. i am using the following code segment to access the database.
Thanks in advance

Code:
FileInputStream inputstream=new FileInputStream(getClass().getResource("hibernate.properties").getFile());
Properties property=new Properties();
property.load(inputstream);
Configuration cfg=new Configuration();
cfg.setProperties(property);
cfg.addClass(Order.class);
cfg.addClass(PurchaseItems.class);
SessionFactory sessionFac=cfg.buildSessionFactory();
Session sess=sessionFac.openSession();
List list=sess.find("from Order as ord where ord.orderid=15");
sess.close();


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 14, 2003 5:21 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Do you commit the transactions?


Top
 Profile  
 
 Post subject: Re:
PostPosted: Sun Dec 14, 2003 12:27 pm 
Newbie

Joined: Tue Sep 16, 2003 4:45 pm
Posts: 14
Hi Gavin,
Yes, i am committing the transactions.I am calling tx.commit(). Where tx is the Transaction object.
The above piece of code segment, is called for every query. I was wondering if I need to call the close on SessionFactory.

Thanks


Top
 Profile  
 
 Post subject: Re: Help
PostPosted: Mon Dec 15, 2003 12:33 am 
Newbie

Joined: Tue Sep 16, 2003 4:45 pm
Posts: 14
Hi,
Could any one please reply to the above query.
Thanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 15, 2003 12:36 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
I dunno what you are doing wrong.


Hold on: you aren't creating a new SessionFactory for each transaction are you??!


Top
 Profile  
 
 Post subject: Re
PostPosted: Mon Dec 15, 2003 10:15 am 
Newbie

Joined: Tue Sep 16, 2003 4:45 pm
Posts: 14
Hi,
Yes, I am .
Thanks


Top
 Profile  
 
 Post subject: Re:
PostPosted: Mon Dec 15, 2003 11:18 pm 
Newbie

Joined: Tue Sep 16, 2003 4:45 pm
Posts: 14
Hi Gavin,
Please suggest, the solution.
Thanks and sorry for the trouble.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 15, 2003 11:30 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
The SessionFactory should be a singleton. Please read the Hibernate documentation. This is very well covered.


Top
 Profile  
 
 Post subject: Re:
PostPosted: Fri Dec 19, 2003 3:12 pm 
Newbie

Joined: Mon Nov 17, 2003 3:50 pm
Posts: 19
I concure, write a singleton for your SessionFactory. Take a look at the springframework if you want to abstract this.

rc wrote:
Hi Gavin,
Please suggest, the solution.
Thanks and sorry for the trouble.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.