-->
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: Conditional Insert
PostPosted: Wed Jan 27, 2010 2:06 pm 
Newbie

Joined: Wed Jan 27, 2010 1:52 pm
Posts: 1
I understand this is a pretty novice question, but after searching for a while, and looking at two books, I still need people help.

I have an object that has a name, address, and telephone number.

User user = new User();
user.setName("Jenny");
user.setAddress("1313 MockingBird");
user.setNumber("8675309");//get it..
//blah session
session.save(user);

Now if I want to add a condition so this user is not added if number 8675309 is present, how. Normally in SQL I can do some if's but I can find out if HQL or Criteria is the way. This has to be in code, I can't put 'Number' field as a primary key, because there are times when this would be allowed.

Basically,
boolean saved = save(user) if ((from User where Address = "8675309") = null)
if(save){
//goto save page
}else{
//error display

I do apologize if this is easy and I just can't find the api for it. Thanks!


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.