Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7409373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:04:27+00:00 2026-05-29T06:04:27+00:00

I have two Hibernate data object. The first is a User (with unique id,

  • 0

I have two Hibernate data object. The first is a User (with unique id, username etc.) and the second is the class Collaborateable. Between this two there is a n-to-m relation (implementet with Sets). That means, a User works on many Collaborateables and a Collaborateable has many users. In addition a Collaborateable has exactly one User as owner.

<class name="CollaborateableImpl" table="Collaborateable">
<id name="id" type="int" column="id">
    <generator class="increment" />
</id>

<property name="name" column="name" type="string" not-null="true" />
<property name="keywords" column="keywords" type="string"/>

<!-- Collaborateable has a Registered User as owner -->
<many-to-one name="owner" class="UserImpl" fetch="select">
        <column name="User_id_owner" not-null="true" />
</many-to-one>

<!-- Users that collaborate on this Collaborateable -->
<set name="users" table="CollaborateOn" inverse="false">        
        <key column="Collaborateable_id" />         
        <many-to-many column="User_id" class="UserImpl" />    
</set>

i would like to implement a Hibernate query, that searches for Collaborateables that have a certain user as owner OR containing the same certain User in the Collaborateable.users Set. In addition, there should also be a simple WHERE clause to check for Keywords.

Is there something like a CONTAINS operator in Hibernate?

For example:

FROM CollaborateableImpl WHERE (owner = :user OR users CONTAINS :user) AND keywords like '%:searchString%'

Otherwise, do you know how to solve this problem with a join?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T06:04:28+00:00Added an answer on May 29, 2026 at 6:04 am

    You’re looking for the elements keyword.

    select c 
    FROM CollaborateableImpl c 
    WHERE (
        c.owner = :user 
        OR :user in elements(c.users)
    )
    AND c.keywords like '%:searchString%'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have following POJO's using Hibernate. public class User { private String
I have a strange Hibernate behaviour in my program. I have two classes with
I use Hibernate with Java. I have two tables which are associated with foreign
I have a hibernate model with two classes, let's say A and B. B
I have a very simple scenario, using NHibernate: one abstract base class animal; two
I have two arrays of System.Data.DataRow objects which I want to compare. The rows
First of all, this is the first time that I use Hibernate so my
i have two tables: Authority , Permission they have many to many relationship class
I have two tables: <class name=Content table=language_content lazy=false> <composite-id> <key-property name=contentID column=contentID/> <key-property name=languageID
I'm using NHibernate 2.1.2 and Spring 1.3 I have two Text columns (blobs) in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.