I created simple DB with LibreOffice Base and exported it with SCRIPT command. It has only one table Tag with “id” and name. I created corresponding class named Tag, with annotation @Entity, and for id @Id.
I load data with following code:
public static void main(String[] args){
Configuration configuration=new Configuration();
configuration.configure();
serviceRegistry=new ServiceRegistryBuilder().applySettings(
configuration.getProperties()).buildServiceRegistry();
sessionFactory=configuration.buildSessionFactory(serviceRegistry);
session=sessionFactory.openSession();
session.beginTransaction();
tag=(Tag) session.get(Tag.class, 1);
session.close();
System.out.println(tag.getName());
}
Running this i get follwing lines:
Hibernate: select tag0_.id as id0_0_, tag0_.name as name0_0_ from Tag tag0_ where tag0_.id=?
and NullPointerException.
in xml file i have specified the file to be used “jdbc:hsqldb:file:testdb”, also added Tag as a mapping class.. What i am doing wrong??
If you use Hibernate+HSQLDB for testing you could set property “hibernate.hbm2ddl.auto” to
“create” – in that case hibernate will create required schema by itself