-->
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.  [ 1 post ] 
Author Message
 Post subject: Add custom fields with spring
PostPosted: Tue Oct 19, 2010 5:03 am 
Newbie

Joined: Tue Oct 19, 2010 5:00 am
Posts: 2
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-fields

However, 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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.