Hello all,
Do anyone know how to add custom field in hibernate if the hibernate configuration file is managed by Spring?
Actually, I found the solution for hibernate only, which is in this link:
http://www.infoq.com/articles/hibernate-custom-fieldsHowever, it do not work if spring is also used.
The error is here:
configuring Hibernate ... failure
org.hibernate.HibernateException: /hibernate.cfg.xml not found
at org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:147)
at org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:1405)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1427)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1414)
at dao.hiber.HibernateUtil.getConfiguration(HibernateUtil.java:41)
at dao.hiber.HibernateUtil.getClassMapping(HibernateUtil.java:73)
at model.CustomizableEntityManagerImpl.getPersistentClass(CustomizableEntityManagerImpl.java:67)
at model.CustomizableEntityManagerImpl.addCustomField(CustomizableEntityManagerImpl.java:36)
I used Spring to manage and so hibernate.cfg.xml does not exist.
So how to modify the below code so that I can get the configuration?
Code:
private synchronized Configuration getConfiguration() {
if (configuration == null) {
System.out.print("configuring Hibernate ... ");
try {
configuration = new Configuration().configure();
configuration.addClass(model.Currency.class);
System.out.println("ok");
} catch (HibernateException e) {
System.out.println("failure");
e.printStackTrace();
}
}
return configuration;
}
Could anyone help me?
Terry.