-->
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: how to catch NonUniqueObjectException and throw a message
PostPosted: Tue May 04, 2010 2:25 pm 
Newbie

Joined: Fri Oct 30, 2009 4:30 pm
Posts: 16
Hi

I am getting a NonUniqueObjectException while I am trying to insert a row into a table. As far as what is happening, it is happening correct. But I would like to catch that exception and display a message back to the user.

I will paste a sample code, so that it gives a better idea of what I am trying to accomplish.

public String addPhdEdPlan() throws HibernateException{

try{
if(this.getAcademicYear() != null && this.getAcademicYear().length()>0){
if(!isDuplicate()){
Short academicYear = Short.valueOf(this.getAcademicYear());
phdDataEdPlan.getId().setAcademicYear(academicYear);
}
}
}catch(NonUniqueObjectException ne){
throw new NonUniqueObjectException("Duplicate academic Year being added for this Student's Education Plan", PhdDataEdPlanId.class, PhdDataEdPlanId.class.getCanonicalName());

/*facesMessages.add("Duplicate academic Year being added for this Student's Education Plan");*/
}

}


So when I try and add a duplicate record, it should display this message on the screen, when the exception occurs.

I hope I have conveyed my intention properly.

Please let me know if it needs clarification.

Hoping to hear soon.

thanks
Sai


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.