You said you were using annotations.  Just read chapter 1 of the hibernate
annotations docs

http://www.hibernate.org/hib_docs/annotations/reference/en/html_single/#setup-configuration

create a class called HibernateUtil.class (or you can call it Fluffy.class,
but that's not as descriptive)
and add a static SessionFactory.

public static final SessionFactory sessionFactory;


Then add an initialize method to add your annotated classes with this:

AnnotationConfiguration cfg = new AnnotationConfiguration();
cfg.configure();
sessionFactory = cfg                    
.setInterceptor(new AuditInterceptor())
.addAnnotatedClass(User.class)
//others as needed
.buildSessionFactory();

The WebApplication object for your project has an init() method.
You can call the above method from there.  When wicket starts
up, it will call that init() method first, so you can do things like
setup your app.

Or just wrap the above in a static block and you don't have to worry 
about it.  The first time you access the HibernateUtil, the class loader
will run the static block.

Then in your methods you can just get a connection from the pool.

Session session = HibernateUtil.sessionFactory.openSession();

I do this a little differently than hibernate examples.  In the service, I
open the connection, get all the data I need and close the connection
at the end of the method.  The way Hibernate works is when your working
thread gets a connection, hibernate attaches that connection to the thread.
So throughout the lifecycle you can make references to related objects and
hibernate will go fetch them for you.  I don't like that technique,
personally.

HTH




-- 
View this message in context: 
http://www.nabble.com/wicket-and-hibernate-tp19767474p19791416.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]

Reply via email to