Note that there are some explanatory texts on larger screens.

plurals
  1. POComparing strings in a JDO query fails when value contains a "Comma"
    primarykey
    data
    text
    <p>I am attempting to check for an existing string using a JDO query, in my attempt to prevent the insertion of a duplicate string.</p> <p>My query to check for an existing string works fine, unless the two strings I am comparing have a comma in the value. If the commas exists, the comparison bombs using "==".</p> <p>For example, if I query to see if "Architecture" exists, I get the right result (Horrray!). If I attempt to see if "Architecture, Engineering, and Drafting" exists, and it does, the query comes back and says an identical value does not exist (Boo!).</p> <p>The code I'm using is as follows:</p> <p><strong>Called from the RPC</strong></p> <pre><code>public void addCommas() { final Industry e = new Industry(); e.setIndustryName("Architecture, Engineering, and Drafting"); persist(e); } public void addNoCommas() { final Industry e = new Industry(); e.setIndustryName("Architecture"); persist(e); } </code></pre> <p><strong>Persist Operation</strong></p> <pre><code>private void persist(Industry industry) { if (industryNameExists(industry.getIndustryName())) { return; } final PersistenceManager pm = PMF.get().getPersistenceManager(); pm.currentTransaction().begin(); try { pm.makePersistent(industry); pm.flush(); pm.currentTransaction().commit(); } catch (final Exception ex) { throw new RuntimeException(ex); } finally { if (pm.currentTransaction().isActive()) { pm.currentTransaction().rollback(); } pm.close(); } } </code></pre> <p><strong>Query</strong></p> <pre><code>public static boolean industryNameExists(final String industryName) { final PersistenceManager pm = PMF.get().getPersistenceManager(); Query q = null; q = pm.newQuery(Industry.class); q.setFilter("industryName == industryNameParam"); q.declareParameters(String.class.getName() + " industryNameParam"); final List&lt;Industry&gt; industry = (List&lt;Industry&gt;) q.execute(industryName.getBytes()); boolean exists = !industry.isEmpty(); if (q != null) { q.closeAll(); } pm.close(); return exists; } </code></pre> <p><strong>JDO Entity</strong></p> <pre><code>@PersistenceCapable(detachable = "true") public class Industry implements StoreCallback { @NotNull(message = "Industry Name is required.") private String industryName; @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) @PrimaryKey private Key key; public Industry() { super(); } public Key getIndustryKey() { return key; } public String getIndustryName() { return industryName; } @Override public void jdoPreStore() { if (industryName != null) { industryName = industryName.trim(); } } public void setIndustryName(final String industryName) { this.industryName = industryName; } } </code></pre> <p>Any thoughts on a resolution or pinpointing an oversight would be very much appreciated. Cheerio.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload