Results 1 to 5 of 5
  1. #1
    Nick15 is offline Member
    Join Date
    May 2007
    Posts
    38
    Rep Power
    0

    Default Search in hibernate

    Hi!
    I have a bean defined with the follow properties:
    Java Code:
    public class UserTopic implements java.io.Serializable {
    private UserTopicId id;
    private Topic topic;
    private int personal = 0;
    -------
    
    UserTopicId is:
    
    -----------
    public class UserTopicId implements java.io.Serializable {
    private String topicId;
    private String userId;
    -----------
    Normally, to search topics for an user I did:
    getHibernateTemplate().find(" from UserTopic where user_id = ?", user_id)

    but I don't know how do I search with this key

    Do you know?

    thanks
    Last edited by Nick15; 06-01-2007 at 12:15 AM.

  2. #2
    Alan is offline Member
    Join Date
    May 2007
    Posts
    39
    Rep Power
    0

    Default

    hi


    try this
    getHibernateTemplate().find(" from UserTopic ut where ut.id.userId = ?",
    user_id)

    bye bye
    alan

  3. #3
    Freddie is offline Member
    Join Date
    May 2007
    Posts
    41
    Rep Power
    0

    Default

    If you have defined the id in the HBM you can do a load:

    (key-many-to-one in hibernate 3).

    session.load(UserTopic.class, new UserTopicId("id","user");

  4. #4
    goldhouse is offline Senior Member
    Join Date
    Mar 2007
    Posts
    134
    Rep Power
    0

    Default

    If you are looking for users starting with the given userID you can use the "Criterion" in hibernate .
    Like this
    Java Code:
    List users = sess.createCriteria(User.class)
        .add( Restrictions.like("name", userID+"%") )
        .list();

  5. #5
    Nick15 is offline Member
    Join Date
    May 2007
    Posts
    38
    Rep Power
    0

Similar Threads

  1. How to search with a Comparator
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-15-2008, 07:39 PM
  2. Search TextFile
    By gsupriyarao@yahoo.com in forum Advanced Java
    Replies: 5
    Last Post: 04-11-2008, 11:03 AM
  3. Search
    By Gilgamesh in forum New To Java
    Replies: 5
    Last Post: 11-26-2007, 03:45 AM
  4. Web Search
    By Marcus in forum Enterprise JavaBeans (EJB)
    Replies: 2
    Last Post: 07-02-2007, 06:51 AM
  5. Replies: 2
    Last Post: 06-30-2007, 03:01 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •