Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / February 2005

Tip: Looking for answers? Try searching our database.

Hibernate and log4j config under Tomcat.

Thread view: 
Rico - 18 Feb 2005 01:54 GMT
"Under Tomcat 3.x and 4.x, you should place the log4j.properties under the
WEB-INF/classes directory of your web-applications. Log4j will find the
properties file and initialize itself. This is easy to do and it works."

"The XML configuration file is placed in the context classpath
(WEB-INF/classes), as hibernate.cfg.xml"

I don't know what's Tomcat's problem but in both cases, despite what the
documentation says, placing the config files in WEB-INF/classes didn't
work.
For log4j I ended up using an initialization servlet.
For Hibernate, I placed the xml file in several folders after some
googling:

WEB-INF/classes ; WEB-INF/classes/<path to class file> ; WEB-INF/src ;
<tomcat_home>/conf

Nothing worked and this time Tomcat explicitly told me that the file is
not to be found. I ended up having to specify an absolute path to at least
see that the code I'm actually interested in works.

I don't know what's Tomcat's problem... or mine...

Rico.
Ryan Stewart - 18 Feb 2005 05:31 GMT
> "Under Tomcat 3.x and 4.x, you should place the log4j.properties under the
> WEB-INF/classes directory of your web-applications. Log4j will find the
[quoted text clipped - 20 lines]
>
> Rico.
Likely yours. I just set up a fresh Hibernate install on Tomcat 5.5 (with Log4j)
with no problems. Define what you mean by "didn't work".
Rico - 18 Feb 2005 07:42 GMT
> "Rico" <ras_nas@yahoo.com> wrote in message

>> "The XML configuration file is placed in the context classpath
>> (WEB-INF/classes), as hibernate.cfg.xml"

>> For Hibernate, I placed the xml file in several folders after some
>> googling:
[quoted text clipped - 11 lines]
> Likely yours. I just set up a fresh Hibernate install on Tomcat 5.5
> (with Log4j) with no problems. Define what you mean by "didn't work".

As I said, for Hibernate under Tomcat (4.1.18 and 4.1.31), no matter where
I put the hibernate.cfg.xml, including WEB-INF/classes, I got the message
that the file is not to be found when we reach the following code:

    sessionFactory = new Configuration().configure()
                        .buildSessionFactory();

    2005-02-18 15:28:00,968 WARN http-8080-Processor4
    net.sf.hibernate.cfg.Configuration - /hibernate.cfg.xml not found

I've considered trying Tomcat 5.0.x but it seems that first I need to
figure out which ones and adapt a couple of settings in server.xml and/or
web.xml to get it to stop crashing.

Rico.
Ryan Stewart - 18 Feb 2005 12:53 GMT
> As I said, for Hibernate under Tomcat (4.1.18 and 4.1.31), no matter where
> I put the hibernate.cfg.xml, including WEB-INF/classes, I got the message
[quoted text clipped - 9 lines]
> figure out which ones and adapt a couple of settings in server.xml and/or
> web.xml to get it to stop crashing.

What version of Hibernate are you using? When I remove the config file, I get
this in the log: (line breaks inserted to prevent wrap and logging set to INFO
level)
INFO [http-8080-Processor25] cfg.Environment (<clinit>:483)
   - Hibernate 2.1.8
INFO [http-8080-Processor25] cfg.Environment (<clinit>:512)
   - hibernate.properties not found
INFO [http-8080-Processor25] cfg.Environment (<clinit>:543)
   - using CGLIB reflection optimizer
INFO [http-8080-Processor25] cfg.Environment (<clinit>:572)
   - using JDK 1.4 java.sql.Timestamp handling
INFO [http-8080-Processor25] cfg.Configuration (configure:909)
   - configuring from resource: /hibernate.cfg.xml
INFO [http-8080-Processor25] cfg.Configuration
   (getConfigurationInputStream:881)
   - Configuration resource: /hibernate.cfg.xml
WARN [http-8080-Processor25] cfg.Configuration
   (getConfigurationInputStream:885)
   - /hibernate.cfg.xml not found
ERROR [http-8080-Processor25] persistence.HibernateUtil (<clinit>:19)
   - Initial SessionFactory creation failed.
   net.sf.hibernate.HibernateException: /hibernate.cfg.xml not found

Does that look like what you're getting? I assume you're using some build tool.
Are you sure that the config file is being built to the right place?
Rico - 18 Feb 2005 16:02 GMT
> What version of Hibernate are you using? When I remove the config file,
> I get this in the log: (line breaks inserted to prevent wrap and logging
[quoted text clipped - 22 lines]
> build tool. Are you sure that the config file is being built to the
> right place?

I was using 2.1.6 and I upgraded to 2.1.8. The above is almost exactly
what I still get. I am positive that I have a file hibernate.cfg.xml in my
application's WEB-INF/classes folder.
It's the same config file that was at the root of the Eclipse project that
didn't require an absolute path to find it.

Rico.
Rico - 19 Feb 2005 15:37 GMT
> "Under Tomcat 3.x and 4.x, you should place the log4j.properties under the
>  WEB-INF/classes directory of your web-applications. Log4j will find the
[quoted text clipped - 20 lines]
>
> Rico.

Believe me, I've really had to keep trying before getting to this point:

Tomcat can now see hibernate.cfg.xml and log4j.properties which are in my
WEB-INF/classes folder as per the documentation.
What isn't in the documentation is whether the absolute path for the web
application needs to be
<CATALINA_HOME>/webapps/<app_folder>/WEB_INF/classes

because from what I observe, only then things work as they are supposed to.
If I am to use another installation path for the application, I'm stuck
with e.g using initialization servlet or probably a ResourceBundle to pass
the path to Hibernate's Configuration class ?

Rico.
Ryan Stewart - 20 Feb 2005 05:27 GMT
> Believe me, I've really had to keep trying before getting to this point:
>
[quoted text clipped - 3 lines]
> application needs to be
> <CATALINA_HOME>/webapps/<app_folder>/WEB_INF/classes

No, it does not.

> because from what I observe, only then things work as they are supposed to.
> If I am to use another installation path for the application, I'm stuck
> with e.g using initialization servlet or probably a ResourceBundle to pass
> the path to Hibernate's Configuration class ?

What do you mean by "another installation path"? What path, and how do you set
it up for Tomcat to access it?
Rico - 20 Feb 2005 12:58 GMT
> "Rico" <ras_nas@yahoo.com> wrote in message
>> Believe me, I've really had to keep trying before getting to this point:
[quoted text clipped - 14 lines]
> What do you mean by "another installation path"? What path, and how do
> you set it up for Tomcat to access it?

C:\\myWebApp

<Context path="/something" docBase="C:\\myWebApp" />

In such a case, Tomcat cannot find
C:\myWebApp\WEB-INF\classes\hibernate.cfg.xml

Same goes for
C:\myWebApp\WEB-INF\classes\log4j.properties

Though from the way I understand the documentation they're supposed to be
found.
It's when I use the following installation folder that e.g
Hibernate's no-args configure() succeeds as Tomcat can find the
hibernate.cfg.xml in:

<CATALINA_HOME>/webapps/<app_folder>/WEB_INF/classes

Rico.
Ryan Stewart - 20 Feb 2005 14:34 GMT
> <Context path="/something" docBase="C:\\myWebApp" />
Try docBase="C:\myWebApp".
Rico - 20 Feb 2005 20:42 GMT
> "Rico" <ras_nas@yahoo.com> wrote in message

>> <Context path="/something" docBase="C:\\myWebApp" />
> Try docBase="C:\myWebApp".

humm... any particular reason why we'd expect that to make a difference?
Ryan Stewart - 21 Feb 2005 19:36 GMT
>> "Rico" <ras_nas@yahoo.com> wrote in message
>
>>> <Context path="/something" docBase="C:\\myWebApp" />
>> Try docBase="C:\myWebApp".
>
> humm... any particular reason why we'd expect that to make a difference?

Not particularly. It's just an inconsistency that I noticed. This is an OS path,
not a Java String. You don't need to escape the '\'s. It *should* work the same
regardless, but you never know. As for your problem in general, either you've
got a corrupted installation or you're not telling some vital bit of
information, because the behavior you've described is not normal. Here is a
complete context that I have saved as
"$CATALINA_BASE\conf\Catalina\localhost\recipes.xml" on WinXP Home:
<Context docBase="C:\Projects\recipes\target\recipes"
       reloadable="true"
       backgroundProcessorDelay="2">
   <Resource name="jdbc/recipes" auth="Container" type="javax.sql.DataSource"
              maxActive="10" maxIdle="2" maxWait="10000"
              username="root" password="root"
driverClassName="com.mysql.jdbc.Driver"
              url="jdbc:mysql://localhost:3306/reciperack"/>
</Context>

Obviously you can ignore the Resource element. The corresponding exploded web
application is at "C:\Projects\recipes\target\recipes", just as in the docBase
attribute. In "C:\Projects\recipes\target\recipes\WEB-INF\classes", I have
hibernate.cfg.xml and log4j.properties, not to mention a Struts resource file,
jndi.properties, and hibernate mapping file, all of which are found on the
classpath when needed.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.