-->
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.  [ 2 posts ] 
Author Message
 Post subject: @PostLoad does not work
PostPosted: Sun Mar 28, 2010 9:48 am 
Beginner
Beginner

Joined: Mon Jan 04, 2010 2:52 pm
Posts: 30
hello,

I would like to use the @PostLoad annotation on a method
so that this method is called after a class is loaded
from persistence (to initialize fields that have been added
and thus are null).

Unfortunately, when I annotate a method (in class Project) with @PostLoad:

@PostLoad
public void debug() {
System.exit(1);
}
this method never gets called (the application doesn't exit).

My application uses a dynamic AnnotationConfiguration, so that
each project gets its own HSQLDB-Database in projects/<name>/projectdb.*:

public static SessionFactory createSessionFactory(String project_name) {
String dbfile = String.format("%s/projectdb", getPath(project_name).getPath());
return new AnnotationConfiguration().configure(new File("hibernate.cfg.xml"))
.setProperty("hibernate.connection.url", String.format("jdbc:hsqldb:file:%s;shutdown=true", dbfile))
.buildSessionFactory();
}

A project is persisted like this:
Transaction tx = session.beginTransaction();
session.saveOrUpdate(prj);
tx.commit();

The session is opened once per Project for the entire Application lifetime
(possible because this is a desktop application - no concurrent accesses).

Do I need to debug hibernate on source-level or does someone
have another idea on what I could try?

Thanks in advance!


Top
 Profile  
 
 Post subject: Re: @PostLoad does not work
PostPosted: Sun Mar 28, 2010 4:45 pm 
Beginner
Beginner

Joined: Mon Jan 04, 2010 2:52 pm
Posts: 30
hello,

I think the problem is that I am using AnnotationConfiguration instead of JPA's EntityManager.
Are there hibernate- (as opposed to JPA-) specific life cycle callback annotations that
I could use?

Thanks!


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