Prepopulating a database on startup
Hi All,
I'm trying to create a simple database pre-populator that checks (on app startup) whether certain data is present in the database, and if it isn't will add it.
I've used Roo to create my domain objects and controllers, but I'm having trouble using my domain objects outside of my Roo-generated controllers.
My pre-population bean doesn't actually do any pre-population at the moment - I'm simply trying to read stuff from the database for now. The code is below -
Code:
@Transactional
@Component
public class DataInitialisationService {
@PostConstruct
public void init() {
List<SiteMember> members = SiteMember.findAllSiteMembers();
System.out.println(members);
}
}
The problem is that my domain object's entityManager() method (implicitly called by invoking findAllSiteMembers) is throwing an exception because Spring hasn't yet injected an entityManager into it!
Having read a couple of forum posts (like this one http://forum.springsource.org/showth...ulate+database), I'm still confused as the guy who posted this actually seems to be getting an entityManager configured on his domain object.
This is likely to be a daft question, but what's the "correct" way to access my Roo-generated domain objects outside of my Roo-generated controllers?
Any suggestions would be much appreciated!
Cheers,
Richard.