-->
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.  [ 6 posts ] 
Author Message
 Post subject: Updated Hello World Example?
PostPosted: Mon Jun 13, 2005 2:02 pm 
Newbie

Joined: Mon Jun 13, 2005 10:48 am
Posts: 4
Hibernate version: 3.05

Hello - First of all thanks for the book - it has been a very good introduction to Hibernate. I do have some questions however.

I've been trying to work through the "Hello World" example, and have hit a couple of snags. On ps. 32 and also on 33 there is the line:

Code:
Session session = getSessionFactory().openSession

However even with adding the appropriate libraries, imports etc. the getSessionFactory() method cannot be found (at least using the IDE I'm using - JBuilder 2005).

Digging into the CaveatEmptor example, instead I noticed that there were the lines:

Code:
SessionFactory factory

and later on:

Code:
Session s = factory.openSession();


Even when trying this though, I get a NullPointerException when the program hits the uninitialized factory.

So I guess I was wondering, is there an updated version of the Hello World program that includes a more complete version of the runnable part? For instance, right now I have:

Code:
package hibernate;

import org.hibernate.*;


public class Hello {

    SessionFactory factory;

    public Hello() {

        Session s = factory.openSession();
        Transaction tx = s.beginTransaction();
        Message message = new Message("Hello World");
        s.save(message);
        tx.commit();
        s.close();

    }

    public static void main(String[] args) {

        Hello h = new Hello();

    }

}


Sorry that this is such a newbie question, but that's why I got the book! Thanks,


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 13, 2005 2:12 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
It's an abstract example! Read the Hibernate3 reference documentation, chapter 2, for a real hands-on, I-don't-know-anything-not-even-Java, where-do-I-have-to-copy-what-file tutorial.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 13, 2005 2:14 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
And if you'd have bothered to read on (like the text recommends if you want to know what getSessionFactory() does), you'd know what a SessionFactory actually is.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 13, 2005 3:33 pm 
Newbie

Joined: Mon Jun 13, 2005 10:48 am
Posts: 4
Thank you very much for your kind reply. The information provided by the reference documentation was very informative.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 14, 2005 5:24 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Hey, thanks for the bad review on Amazon!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 14, 2005 5:31 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
On second thought, banned the user. For everyone else who doesn't understand the word "abstract": It means you can't just type it in and run it, you have to fill in some things that are abstract and explained 5 pages later (which is also mentioned). But I guess reading is too much a skill these days.


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