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.  [ 2 posts ] 
Author Message
 Post subject: Simple Validation
PostPosted: Fri Apr 04, 2008 4:32 pm 
Newbie

Joined: Fri Apr 04, 2008 4:22 pm
Posts: 1
Hello, I want to know if it's possible, or what's the appropriate way to do a simple input validation on a model object. I have a class (Book) mapped to a table, I'd like to assure that no two books exist with the same title, and author name. I've added the appropriate restrictions in the database, but I think it's still needed another level of validation.

If NHibernate does not helps in this, what would you suggest as the appropriate place for such validation?

Anyway, thanks for the attention!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 07, 2008 7:55 am 
Beginner
Beginner

Joined: Sun Aug 12, 2007 11:22 am
Posts: 44
Location: Sweden
Is it in a webapplication or windows application?


create a method like this

Code:
public Boolean exists( Book book ){
  /** Check here if the book exists*/

  ... SELECT b FROM Book b WHERE b.Id != :id AND b.Name = :Name  AND b.Title = :Title;

  /** add parameters here */
   

   return true or false if we got a book
}


In this way you will be able to update the book that has this id but no new book with the same id, title and name.

Code:
public Book addBook( Book book ){
   if( ! exists( book ) ){
    // Add here
  }

  // return null or something that indicates that the book wasn't added
}




Please let me know if you need furthur help


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.