-->
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.  [ 7 posts ] 
Author Message
 Post subject: Programmatic configuration
PostPosted: Sun Oct 11, 2009 2:50 am 
Newbie

Joined: Sun Oct 11, 2009 2:43 am
Posts: 7
Hi,
Actually I want to configure my properties without using hibernate.cfg files,
everything I am able to do ,still it gave an error like
org.hibernate.HibernateException: No CurrentSessionContext configured!

but for that i have also set the property

lo.setProperty("current_session_context_class", "thread");

but still not worked!

If anybody has worked over it?

Please reply ASAP!


Top
 Profile  
 
 Post subject: Re: Programmatic configuration
PostPosted: Sun Oct 11, 2009 5:30 pm 
Senior
Senior

Joined: Mon Jul 07, 2008 4:35 pm
Posts: 141
Location: Berlin
Hi nitin.mahajan,

could you probably post the whole stack trace of your exception? And if you have your programmatic configuration set up at hand, please post it, too.

CU
Froestel

_________________
Have you tried turning it off and on again? [Roy]


Top
 Profile  
 
 Post subject: Re: Programmatic configuration
PostPosted: Mon Oct 12, 2009 2:20 am 
Newbie

Joined: Sun Oct 11, 2009 2:43 am
Posts: 7
Hi dude,
Thanks for reply
Actally i am connecting to database at runtime,so all parameters are passed depends on client ,

public static void createSessionFactoryClient(String fsDBUrl, String fsUserName, String fsPwd) {
Configuration lo = new Configuration();

lo.setProperty("hibernate.connection.url", fsDBUrl);
lo.setProperty("hibernate.connection.username", fsUserName);
lo.setProperty("hibernate.connection.password", fsPwd);
lo.setProperty("hibernate.connection.zeroDateTimeBehavior", "convertToNull");
lo.setProperty("connection.autoReconnect", "true");
lo.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
lo.setProperty("hibernate.connection.driver_class", "com.mysql.jdbc.Driver");
lo.setProperty("current_session_context_class", "thread");

//and all pojo classess are also mapped

}

it is giving exception like..........
org.hibernate.HibernateException: No CurrentSessionContext configured!
at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:542)
at com.struts2Dispatcher.HibernateUtil.getSessionClient(HibernateUtil.java:231)

It is working fine ,if i mapped hibernate .cfg.xml and put
<property name="current_session_context_class">thread</property>


Top
 Profile  
 
 Post subject: Re: Programmatic configuration
PostPosted: Mon Oct 12, 2009 11:22 am 
Senior
Senior

Joined: Mon Jul 07, 2008 4:35 pm
Posts: 141
Location: Berlin
Hi nitin.mahajan,

maybe you have a typo somewhere. Try, and prepend hibernate. to the string to look like
Code:
lo.setProperty("hibernate.current_session_context_class", "thread");

There are preconfigured String constants for that purpose in the org.hibernate.cfg.Environment class. You can view a list of these String constants here.

CU
Froestel

_________________
Have you tried turning it off and on again? [Roy]


Top
 Profile  
 
 Post subject: Re: Programmatic configuration
PostPosted: Mon Oct 12, 2009 12:58 pm 
Newbie

Joined: Sun Oct 11, 2009 2:43 am
Posts: 7
Hi Froestel,

Finally it worked!!

Thank you very much,it was so silly mistatke ,but still it took 2 days to solve it,thanks very much once again for your precise time and suggestions!

I want to ask question related to it,is programmatic conf will take less time as compare to hibernate.cfg.xml?

As it was suggested by one of my friend!


Top
 Profile  
 
 Post subject: Re: Programmatic configuration
PostPosted: Mon Oct 12, 2009 4:51 pm 
Senior
Senior

Joined: Mon Jul 07, 2008 4:35 pm
Posts: 141
Location: Berlin
Hi nitin.mahajan,

nitin.mahajan wrote:
Finally it worked!!

Great! Congratulations!

nitin.mahajan wrote:
I want to ask question related to it,is programmatic conf will take less time as compare to hibernate.cfg.xml?

As it was suggested by one of my friend!


Can't say - I've never done any performance tests on this issue.
But if you take into account: Reading a file from the hard disk certainly takes some time. Additionally, in this case it is an XML file that has to be parsed before the configuration data can actually be handled. This all is additional overhead compared to programmatic configuration, I guess.

CU
Froestel

_________________
Have you tried turning it off and on again? [Roy]


Top
 Profile  
 
 Post subject: Re: Programmatic configuration
PostPosted: Tue Oct 13, 2009 8:59 am 
Newbie

Joined: Sun Oct 11, 2009 2:43 am
Posts: 7
Thanks Froestel!
As you said,same thoughts were in my mind,that's why I preffered programmatic configuration,

Actually When any new client registerd then each time I am generating a new DB for each user,so when he/she login in to the system.Our system reads whole the hibernate.cfg file,so it takes bit more time on a server!

Can you suggest other extra things that I can do to speed up my hibernate processing?

Thanking You,
Regards,
Nitin


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.