Posts Tagged ‘getInstance()’

HibernatePersistenceService

Wednesday, October 17th, 2007

I have just had a look for an example how to use the HibernatePersistenceService in trails properly….as I could not find any code, I have tried to do the following:

HibernatePersistenceService service = (HibernatePersistenceService)this.getPersistenceService(); if (service != null){

User user = service.getInstance(User.class);

Unfortunately, this is not working as no User instance is returned - and all successive method calls on user lead to a NullPointerException.

The solution 

The solution is: You simply call the constructor of your data object….you do not need the getInstance() method at all.

Another error was, that the generated hibernate.cfg.xml file has not picked up the new data objects and therefore they were missing in the configuration file. So I have simply edited the file in the classes folder. Later I noticed those objects where not included as some setter methods were missing and so they were ignored….