Question

I have 3 tables in Oracle DB which relationship is @ManyToMany. So I have 2 significant tables and one for mappings.

I create a classes with name (if you want I can show my classes) named Entities, Keywords (I understand that naming is not correct but this is not my project I only do optimizations).

I use hibernate version 4.3.4.

I write query like this:

        session = HibernateUtil.getSessionFactory().openSession();
        String sql = "SELECT DISTINCT r FROM Rules r, Entities e " +
                " WHERE r.entities = e.rules " +
                "  AND e IN :entities ";

        Query query = session.createQuery(sql);
        query.setParameterList("entities", entitiesList);

        List<Rules> rulesList = query.list();

BUT! Hibernate generate strange SQL

Hibernate: 
select
    rules0_.rule_id as rule_id1_11_,
    rules0_.rule as rule2_11_ 
from
    rules rules0_,
    entities entities1_,
    rules_entities entities2_,
    entities entities3_,
    rules_entities rules4_,
    rules rules5_ 
where
    rules0_.rule_id=entities2_.rule_id 
    and entities2_.entity_id=entities3_.entity_id 
    and entities1_.entity_id=rules4_.entity_id 
    and rules4_.rule_id=rules5_.rule_id 
    and .=.
    and (
        entities1_.entity_id in (
            ? , ? , ? , ?
        )
    )

When I try to execute this query I receive that error: java.sql.SQLException: ORA-00936: missing expression

When I copy this query to OracleDevepoler he didn`t like this expression "and .=.". Without that query executes correct.

What am I doing wrong ?

Was it helpful?

Solution

Maybe you used bad join in your query? From context i conclude that you should use something like that:

"SELECT DISTINCT r FROM Rules r inner join r.entities e " +
                "  WHERE e IN :entities ";

OTHER TIPS

I think the correct query could be

select distinct e.rules from Entities where e.entityId in :entities

This is if Keywords is your join table and you have a collection of rules in Entities

If it isn't, can you show the mappings please, it could help.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top