File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes hibernate.cfg.xml problem on startup Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "hibernate.cfg.xml problem on startup" Watch "hibernate.cfg.xml problem on startup" New topic
Author

hibernate.cfg.xml problem on startup

jim mcnamara
Ranch Hand

Joined: Jun 13, 2007
Posts: 64
hi-



i've noticed that hibernate is pulling settings out of memory somehow.
i tried to set my hibernate.cfg.xml and put the db path in
/usr/lib/JADE/hibernate.cfg.xml

but the probelm is that even after i go in and change the file
/usr/lib/JADE/hibernate.cfg.xml, iit might pick up a prior setting .

it definitely has a mind of its own on start up and i'd really like to
know why on startup it isnt reading my hibernate.cfg.xml

what i am trying to do is let the user edit the hibernate.cfg.xml
in /usr/lib/JADE and change the db path to anywhere on their system.

thanks for any assistance - 3rdshiftcoder

here is my hibernate.util:
-----------------------------------------------------------------------------------------------------------------------------------

package db2;







import org.hibernate.*;

import org.hibernate.cfg.*;

import org.dom4j.*;

import java.io.File;



public class HibernateUtil {

private static SessionFactory sessionFactory;



static {

try {





AnnotationConfiguration cfg = (AnnotationConfiguration) new AnnotationConfiguration();



cfg.addAnnotatedClass(GLMaster.class);

cfg.addAnnotatedClass(GLDetailRecord.class);

cfg.addAnnotatedClass(Category.class);

cfg.addAnnotatedClass(Invoice.class);

cfg.addAnnotatedClass(InvoiceDetail.class);

cfg.addAnnotatedClass(Payeeor.class);



cfg.configure(new File("/usr/lib/JADE/hibernate.cfg.xml"));

cfg.buildSessionFactory();









} catch (Throwable ex) {

throw new ExceptionInInitializerError(ex);

}

}

public static SessionFactory getSessionFactory() {

// Alternatively, you could look up in JNDI here

return sessionFactory;

}

public static void shutdown() {

// Close caches and connection pools

getSessionFactory().close();

}

}
my hibernate.cfg.xml
-----------------------------------------------------------------------------------------------------------

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.bytecode.use_reflection_optimizer">false</property>
<property name="hibernate.connection.driver_class">org.apache.derby.jdbc.EmbeddedDriver</property>
<property name="hibernate.connection.password">user1</property>
<property name="hibernate.connection.url">jdbc:derby:/home/thirdshift/JADE_DB</property>
<property name="hibernate.connection.username">user1</property>
<property name="hibernate.dialect">org.hibernate.dialect.DerbyDialect</property>
<mapping class="db2.GlLineItem" />
<mapping class="db2.GLMaster" />
<mapping class="db2.Category" />
<mapping class="db2.Invoice" />
<mapping class="db2.InvoiceDetail" />
</session-factory>
</hibernate-configuration>



jim mcnamara
Ranch Hand

Joined: Jun 13, 2007
Posts: 64


i dont know man. it (my program) seems to be working.
i have it set up so the db is in /usr/lib/JADE

i figure if i put the db there and leave the db name always
JADE_DB then i am safe.

i had initially thought i'd like for the user to be able to move
the db around on the pc but hibernate is out of its mind today.

either that will or wont be acceptable to the user.

i am putting it up on my site now. it should be up in another
1/2 hour. www.3rdshiftcoder.com

i guess never mind the question. if anyone would check it out,
that would be cool. that way i have feedback on my deployment
on another machine. if not, i understand.

thanks,
3rdshiftcoder
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: hibernate.cfg.xml problem on startup
 
Similar Threads
I'm not able to insert record in Derby using Hibernate
Could not read mappings from resource ?
Session creation falied - error
Accessing hibernate.cfg.xml from web project through JAR file
glassfish vs. Hibernate: JNDI configuration