-->
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.  [ 14 posts ] 
Author Message
 Post subject: hibernate.cfg.xml question
PostPosted: Tue May 08, 2007 4:26 pm 
Newbie

Joined: Tue May 08, 2007 3:34 pm
Posts: 19
I did look at some of the faqs and posts, but did not find any ideas to help. I have an application that supports several customers which each have their own schema name. They all run under five different application servers. I created subfolders for each customer to store the customer specific hibernate.cfg.xml file. I need to be able to specifty a path to the CONFIG_FILE_LOCATION in HibernateSessionFactory.java.

Something like this at runtime: CONFIG_FILE_LOCATION = /customer1/hibernate.cfg.xml

I am looking into different ideas, but wanted to post this in case someone has encountered anything similar.

Thanks in advance for any help!
Joe


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 08, 2007 4:37 pm 
Newbie

Joined: Tue May 08, 2007 11:28 am
Posts: 10
Wherever you create your sessions, try:
Code:
Configuration cfg = new Configuration().configure(CONFIG_FILE_LOCATION);


If you need to add your connection config on the fly, you can do this:

Code:
   Properties p = new Properties();
   p.put("hibernate.connection.url", url);
   p.put("hibernate.connection.username", username);
   p.put("hibernate.connection.password", password);
   p.put("hibernate.default_catalog", databaseName);
   cfg = cfg.addProperties(p);


And then the finishing touch:

Code:
SessionFactory sf = cfg.configure().buildSessionFactory();


Top
 Profile  
 
 Post subject: stack overflow
PostPosted: Wed May 09, 2007 4:39 pm 
Newbie

Joined: Tue May 08, 2007 3:34 pm
Posts: 19
I am getting the following stack trace after trying to add in the changes.

Server rapidreview ready (startup time: 23 seconds)
09 May 2007 15:59:37 [web-0] INFO -Hibernate 3.0.5
09 May 2007 15:59:37 [web-0] INFO -hibernate.properties not found
09 May 2007 15:59:37 [web-0] INFO -using CGLIB reflection optimizer
09 May 2007 15:59:37 [web-0] INFO -using JDK 1.4 java.sql.Timestamp handling
09 May 2007 15:59:37 [web-0] DEBUG -getting Roles instance with id: 3
05/09 15:59:37 error
[1]java.lang.StackOverflowError
[0]javax.servlet.ServletException
at jrun.jsp.runtime.Utils.handleException(Utils.java:61)
at jrun.jsp.runtime.JRunPageContext.handlePageException(JRunPageContext.java:384)
at jrun__GUIs__Roles2ejspf._jspService(jrun__GUIs__Roles2ejspf.java:70)
at jrun.jsp.runtime.HttpJSPServlet.service(HttpJSPServlet.java:43)
at jrun.jsp.JSPServlet.service(JSPServlet.java:119)
at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:91)
at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42)
at jrun.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java:252)
at jrun.servlet.ServletEngineService.dispatch(ServletEngineService.java:527)
at jrun.servlet.http.WebService.invokeRunnable(WebService.java:168)
at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.java:451)
at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)

Any ideas what is run would be appreciated!
THanks,
Joe


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 09, 2007 4:55 pm 
Newbie

Joined: Tue May 08, 2007 11:28 am
Posts: 10
Quote:
09 May 2007 15:59:37 [web-0] INFO -hibernate.properties not found


Looks like you're referring to a hibernate.properties file that doesn't exist or is not on the classpath.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 09, 2007 5:45 pm 
Newbie

Joined: Tue May 08, 2007 3:34 pm
Posts: 19
Thanks for all your help!


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 10, 2007 11:46 am 
Newbie

Joined: Tue May 08, 2007 3:34 pm
Posts: 19
I am using MyEclipse to generate the code. I don't see where hibernate.properties is used at all. The only configuration files created are: hibernate.cfg.xml and all the mapping files for each table. I would like to be abe to configurable some options. Any ideas?

There is a lot of output once an object gets created. Is there a way to turn off all the DEBUG outputs during production?


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 10, 2007 12:30 pm 
Newbie

Joined: Tue May 08, 2007 3:34 pm
Posts: 19
Here is the code I added and it does not cause any exceptions, but does not work as desired. The main problem I have is when this code runs it uses the default values stored in hibernate.cfg.xml adn not the value passed in. Any ideas? Thanks.

public void resetCustomer(){
System.out.println("Enter resetCustomer");
try {
if(userName != null &&
password != null &&
schemaName != null){

System.out.println("*****Entering if userName not null ");
Properties p = new Properties();
//p.put("hibernate.connection.url", url);
p.put("hibernate.connection.username", userName);
p.put("hibernate.connection.password", password);
p.put("hibernate.default_schema", schemaName);
configuration = configuration.addProperties(p);
configuration.configure(configFile);
sessionFactory = configuration.buildSessionFactory();
}


} catch (Exception e) {


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 10, 2007 12:52 pm 
Newbie

Joined: Tue May 08, 2007 11:28 am
Posts: 10
Please post your hibernate config. For the sake of readability and length, cut most of your mapping references unless you feel like certain mappings have an impact on the problem.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 10, 2007 2:24 pm 
Newbie

Joined: Tue May 08, 2007 3:34 pm
Posts: 19
<hibernate-configuration>
<session-factory>
<property name="connection.username">aacr20</property>
<property name="connection.url">
jdbc:oracle:thin:@richtestdb01:1521:devrapid
</property>
<property name="dialect">
org.hibernate.dialect.Oracle9Dialect
</property>
<property name="connection.password">aacr20</property>
<property name="connection.driver_class"> oracle.jdbc.driver.OracleDriver
</property>
<property name="show_sql">false</property>
<property name="use_sql_comments">false</property>

<mapping resource="Author.hbm.xml" />
<mapping resource="AllTags.hbm.xml" />
<mapping resource="AuLogin.hbm.xml" />


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 10, 2007 3:20 pm 
Newbie

Joined: Tue May 08, 2007 11:28 am
Posts: 10
I'm not sure if you can override values that are in the hibernate configuration file. I suggest either stripping those from the config file or, I believe you said your first option was to make a new hibernate configuration file for each schema. Whatever makes the most sense for your environment.

Also, with regard to your other post on the debug output, if you are getting sql output, change show-sql to false in your hibernate config file, you can also do this through a hibernate properties file so you can have a version of the file on dev that shows sql and a version on prod that doesn't without having to change the actual config xml file. Other than that, debug statements are a result of your logger configuration. Set the hibernate packages to warn or info if you want to get rid of those logging statements, but they are quite helpful in development.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 10, 2007 5:04 pm 
Newbie

Joined: Tue May 08, 2007 3:34 pm
Posts: 19
It works once I removed the properties from the hibernate.cfg.xml file. That was very helpful. I am still running into problems with the logging to stdout. A ton of information that is ok during development.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 10, 2007 5:44 pm 
Newbie

Joined: Tue May 08, 2007 11:28 am
Posts: 10
mnishizawa wrote:
Also, with regard to your other post on the debug output, if you are getting sql output, change show-sql to false in your hibernate config file, you can also do this through a hibernate properties file so you can have a version of the file on dev that shows sql and a version on prod that doesn't without having to change the actual config xml file. Other than that, debug statements are a result of your logger configuration. Set the hibernate packages to warn or info if you want to get rid of those logging statements, but they are quite helpful in development.


This section of my last post should help you with limiting the output. In your log4j file(make sure there isn't one that you are unaware of on the classpath), you can specify the log levels of different packages individually. See the log4j docs for this info.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 11, 2007 8:28 am 
Newbie

Joined: Tue May 08, 2007 3:34 pm
Posts: 19
They have appenders for different output files. These appenders are defined in log4j.xml file which does not specify any classes for output. It appears all third party outputs are not included in the logging. When they do there logging they use a specific appender to write to the appropriate log file. I tried adding a log4j.properties to a folder that is in the classpath, but does not seem to work. I know this is off topic from Hibernate, and I do appreciate your insight.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 11, 2007 8:50 am 
Newbie

Joined: Tue May 08, 2007 11:28 am
Posts: 10
Check out the second comment in this post. You can either use OFF or move to any level(WARN, ERROR, FATAL and so on). I would not suggest using OFF since it could prevent logging of real errors.


If you're going the xml route, I would stay with that. There should be something equivalent to log4j.logger.<package name>


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