Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: How do I do a search using my class as a parameter?
PostPosted: Fri Mar 16, 2012 3:10 pm 
Newbie

Joined: Wed Oct 14, 2009 3:22 pm
Posts: 16
Hi,

I'm using Hibernate 4.0.1. I have a class User mapped to my USERS table. A sample of the fields are below ...

Code:
@Entity
@Table(name = "USERS")
public final class Registration implements UserDetails, Serializable {

   @Id
   @Column(name = "ID")
   @GeneratedValue(strategy=GenerationType.AUTO)
   private Integer id;

   @NotEmpty
   @Column(name = "USERNAME")
   private String username;
   @NotEmpty
   @Size(min = 4)
   @Column(name = "PASSWORD")
   private String password;
   @Transient
   private String confirmPassword;
   @NotEmpty
   @Email
   @Column(name = "EMAIL")
   private String email;
   @Column(name = "FIRST_NAME")
   private String firstName;
   @Column(name = "LAST_NAME")
   private String lastName;
   @OneToMany(fetch = FetchType.EAGER, targetEntity = EventFeed.class)
    @JoinTable(name = "USER_EVENT_FEEDS", joinColumns = { @JoinColumn(name = "USER_ID") }, inverseJoinColumns = { @JoinColumn(name = "EVENT_FEED_ID") })
   private Set<EventFeed> userEventFeeds = new HashSet<EventFeed>(0);
   @OneToMany(fetch = FetchType.EAGER, targetEntity = Role.class)
    @JoinTable(name = "USER_ROLES", joinColumns = { @JoinColumn(name = "USER_ID") }, inverseJoinColumns = { @JoinColumn(name = "ROLE_ID") })
   private Set<Role> userRoles = new HashSet<Role>(0);


How would I do a search on the non-null fields of a User object? In other words, if the User object only contained a non-null firstName field, I would want to do a search on all users with a matching first name.

Thanks, - Dave


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 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.