0

I'm using jinq version 1.8.11 with hibernate version 4.3 Using hibernate session factory and not entity manager.

I'm trying the following query:

JPAJinqStream<Routine> routineStream = stream.streamAll(getCurrentSession(), Routine.class);

    if (text.isPresent()) {
        final String searchText = text.get();
        routineStream = routineStream
                .leftOuterJoin(
                        (r, source) -> source.stream(NLSProperty.class),
                        (r, nls) -> nls.getVarKey().equals("routine.100.title")
                ).select(pair -> pair.getOne());"%" + searchText + "%")).select(Pair::getOne);
    }
    List<Routine> tp = routineStream.toList();

When the variable text is not present the query works and I get results. When the variable text is present I'm getting the following error:

java.lang.IllegalStateException: DOT node with no left-hand-side!

any ideas what am I doing wrong?

I have debug the jinq and the query it's generating looks like this:

SELECT A FROM de.etherapists.ehealth.model.routine.Routine A LEFT OUTER JOIN de.etherapists.ehealth.model.NLSProperty B ON B.varKey = 'routine.100.title';

Thanks

Amitai
  • 43
  • 8
  • The resulting query String JOIN does not contain a Link between A and B. I think this is what Hibernate complains about. What is the query you would actually expect? How do your Entity classes look like (especially the foreign key definitions). – Selaron Nov 28 '18 at 11:09
  • Hi, The entities aren't contected with onetomany or manytomany annotations. The query I expect would look like this SELECT * FROM routines r left outer JOIN nlsproperties n ON n.varKey = CONCAT('routine.', r.id, '.title'); – Amitai Nov 28 '18 at 11:30
  • Never saw a `concat` within a `join` condition - is that legit at all? (really not sure). How about `select * from routines r, nslproperties n where n.varKey = CONCAT('routine.', r.id, '.title');` ? – Selaron Nov 28 '18 at 11:59
  • well I can also change the query to be something like [SELECT * FROM routines r left JOIN nlsproperties n ON n.varKey = r.title;] since the query you suggested giving me wrong results – Amitai Nov 28 '18 at 12:28

1 Answers1

0

Ok so I upgraded hibernate version to 5.1 Still using the session factory and not entity manager.

and the code is now:

if (text.isPresent()) {
        routineStream = routineStream
                .leftOuterJoin(
                        (routine, source) -> source.stream(NLSProperty.class),
                        (routine, nls) -> routine.getTitle().equals(nls.getVarKey())
                )
                .where(pair -> JPQL.like(pair.getOne().getShortCode(), "%" + text + "%")
                        || JPQL.like(pair.getTwo().getVarValue(), "%" + text + "%"))
                .select(Pair::getOne)
    }

and it works like a charm

Amitai
  • 43
  • 8