Whenever I try to get that row that I just inserted, using the above hibernate query, I get a list with one element which is NULL.If I try to get the same row but directly in Oracle, using the query that underlying was generated by hibernate, then I'm able to get that row that was inserted without problems.

So my question is: Why hibernate is not able to get that row that was inserted?

Try using an embeddable id instead. Maybe there's an issue with the way composite ids are handled by this query.

I don't think I can use embeddable id. This would be like to use @idClass, right?. Then, none of fields that belong to the index can be null, and what I need is to allow that column2 or column3 can be null.

It's not an IdClass. Check the Hibernate 5.2 documentation link that I gave you. Also, a Primary Key is not allowed to use NULL because NULL means UNKNOWN in database terms.

Yes, no problem with the primary key concept :) .

Let me explain you why I'm asking these weird things: someone created in the DB that unique index that I posted in the first comment. Why that person did that? basically to ensure that the combination of column1+column2+column3 was always different, allowing nulls values in that combination for column2 and column3.

Then this person, added @Idclass in the hibernate entity, which obviusly produced errors (since the pk can't include null values).

We don't want to change the DB structure, nor the values that historically have been there.

So I was trying to apply some ""fix"" from the hibernate side. But looks like there's no other way than modify the DB structure OR modify those nulls values in the DB to have some default value.

So that is the reason that I think the embeddable ids strategy won't work. Whatever I do, if there are any null value. Then, Hibernate will explote.

I wanted to mention, because I just had this problem, that if any of those columns you are using for your composite key are NULL, than Hibernate will return null objects. I was pulling everything from a View and one of the columns was all null so hibernate was returning a list with the right number of items in it, but all the items were null. In my case I couldn't modify the field, so I just removed it from the Key

But what's the PK of that table? You can use that PK as an identifier and leave that UNIQUE INDEX which doesn't really enforce strict unicity since it allows null values.

That's the point. That table doesn't have any PK, like the script is showing. So actually we have been trying to ""fix"" an issue from the wrong side ( hibernate) just because we wanted modify the DB ( therefore, take care about all the issues that might trigger in production)

Finally we decided to add a new column in that table ( a sequence which will be the PK).Which was what I wanted from the very start.