Typically the hibernate.cfg.xml is located in the root of your
packages and the configuration is loaded in the application like this:
hibernateConfig = new AnnotationConfiguration();
URL cfg = getClass().getResource("/hibernate.cfg.xml");
hibernateConfig.configure(cfg);
Your main problem is that you cannot get to the webapps directory from
within the application's classloader.
Maurice
On Tue, Mar 18, 2008 at 1:50 PM, tbt <[EMAIL PROTECTED]> wrote:
>
> Hi
>
> I'm new to hibernate and I have a problem as the wicket page class does not
> detect the hibernate.cfg.xml file
> The code is as follows
>
> public class InfoPage extends WebPage
> {
> private static Logger log =
> Logger.getLogger(InfoPage.class.getName());
>
> public InfoPage()
> {
> Session session = null;
>
> try{
>
> // This step will read hibernate.cfg.xml and prepare
> hibernate for use
> SessionFactory sessionFactory = new Configuration()
>
>
> .configure("webapps/ExampleHib/Resources/hibernate.cfg.xml").buildSessionFactory();
> session =sessionFactory.openSession();
> //Create new instance of Contact and set
> values in it by reading them
> from form object
> log.info("Inserting Record");
> Contact contact = new Contact();
> contact.setId(6);
> contact.setFirstName("Deepak");
> contact.setLastName("Kumar");
> contact.setEmail("[EMAIL PROTECTED]");
> session.save(contact);
> log.info("Done");
> }catch(Exception e){
> e.printStackTrace();
> }finally{
> // Actual contact insertion will happen at this step
> session.flush();
> session.close();
>
> }
> }
> }
>
> The hibernate.cfg.xml file is in ExampleHib/Resources/hibernate.cfg.xml
> folder. The application is run on tomcat. Is this the correct way to do
> this. Please provide your feedback as the way to integrate wicket with
> hibernate in a very simple example as I am new to hibernate.
>
> tbt
> --
> View this message in context:
> http://www.nabble.com/hibernate-tp16120516p16120516.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]