166 words

String Contains Query Result - Possible?

2017-09-11 17:56


I have a managed database for an Entity, "Program", containing a String field, "description", that is effectively a unique sub-string of a system generated description.

System: For Series Sales usage: 6014-Private Individual Swim Lessons  10-Pack
Database: 6014-Private Individual Swim Lessons  10-Pack

I would like to know if it is possible to have a query return the "Program" object using the System Description?

I've considered doing something similar to...

SELECT FROM Program WHERE description LIKE " [something] "

...but, this doesn't seem like it will work even when using wildcards as the input string will be larger than the string being searched for.

Presently, the only solution I have is to iterate over all the Program objects manually and find one that is contained within the System Description.

public static Program programByDescription(String desc)
  for(Program p : allPrograms())
    return p;
  return null;

Is there a more optimal way to do this?

DragonRulerX's picture
Joined on 2017-07-26
User Post #10
2017-09-12 12:55

You can use JPQL Locate:

SELECT FROM Program WHERE LOCATE(" [something] ", description) > 0


ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
support's picture
Joined on 2010-05-03
User Post #2,811

Post Reply

Please read carefully the posting instructions - before posting to the ObjectDB website.

  • You may have to disable pop up blocking in order to use the toolbar (e.g. in Chrome).
  • Use ctrl + right click to open the browser context menu in the editing area (e.g. for using a browser spell checker).
  • To insert formatted lines (e.g. Java code, stack trace) - select a style in the toolbar and then insert the text in the new created block.
  • Avoid overflow of published source code examples by breaking long lines.
  • You may mark in paragraph code words (e.g. class names) with the code style (can be applied by ctrl + D).
  • Long stack traces (> 50 lines) and complex source examples (> 100 lines) should be posted as attachments.
Maximum file size: 32 MB