-->
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.  [ 4 posts ] 
Author Message
 Post subject: Help on Hibernate Mapping
PostPosted: Thu Feb 26, 2009 10:29 am 
Newbie

Joined: Tue Feb 10, 2009 6:01 am
Posts: 3
Location: LAgos
please i have an open source project i am working on and i need help as regards to limiting certain retrival from the database.
it goes like this.
i do not want to make money deposited in an account avaialble for withdrawal if the deposited amount is above more than 500,000.
i have a working table that uses hbm.xml mapping to reteive and insert
any ideas will be appreicated.
thanks

_________________
Laa


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 27, 2009 12:51 am 
Expert
Expert

Joined: Fri Jan 30, 2009 1:47 am
Posts: 292
Location: Bangalore, India
Ideally this should be done in the business layer. Or you can incorporate this logic into the setter of the withdrawal amount or use an Interceptor.onSave method to implement this.

_________________
Regards,
Litty Preeth


Top
 Profile  
 
 Post subject: thx
PostPosted: Fri Feb 27, 2009 4:04 am 
Newbie

Joined: Tue Feb 10, 2009 6:01 am
Posts: 3
Location: LAgos
i understand the aspect of using setter to solve the problem which i am having problem comapring the money type with the threshold value.
i also need you to explain a little about the interceptor u mention how can that be achived?
thx

_________________
Laa


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 27, 2009 4:28 am 
Expert
Expert

Joined: Fri Jan 30, 2009 1:47 am
Posts: 292
Location: Bangalore, India
You can have something like this:
Code:
public class MyInterceptor extends EmptyInterceptor {

   public boolean onSave(Object entity, Serializable id, Object[] state,
         String[] propertyNames, Type[] types) throws CallbackException {
      if(entity instanceof Withdrawal) {
         Withdrawal itm = (Withdrawal) entity;
         if(itm.getAmount() > 500000) {
            throw new CallbackException("Withdrawal limit exceeded");
         }
      }
      return false;
   }
}


Now while opening a session you can use this interceptor like:
Code:
Session session = HibernateUtil.getSessionFactory().openSession(new MyInterceptor());
      session.beginTransaction();
.............
.............

_________________
Regards,
Litty Preeth


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

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.