Note that there are some explanatory texts on larger screens.

plurals
  1. PODataNucleus Enhancer, JDO and Specifying Column Names
    text
    copied!<p>I'm working with DataNucleus as part of a Google App Engine project and I'm having a bit of trouble with columns in persistence.</p> <pre><code>@PrimaryKey(column = "user_id") @Column(name = "user_id") @Persistent(name = "user_id", column = "user_id", valueStrategy = IdGeneratorStrategy.IDENTITY) private Key m_id; @Column(name = "user_name") @Persistent(name = "user_name", column = "user_name") private String m_userName; </code></pre> <p>If you can't tell, I'm trying to name the column something different than the name of the variable because I have two naming conventions (one works better in Java, one works better in SQL). Anyway, I've tried all variations of those marker annotations but the DataNucleus enhancer refuses to honor any of them, so when I run a query like this:</p> <pre><code>Query q = pm.newQuery(User.class, "user_name == _username"); </code></pre> <p>I always get an error like this:</p> <blockquote> <p>org.datanucleus.store.appengine.FatalNucleusUserException: Unexpected expression type while parsing query. Are you certain that a field named user_name exists on your object?</p> </blockquote> <p>Of course, when a run a query like this:</p> <pre><code>Query q = pm.newQuery(User.class, "m_userName == _username"); </code></pre> <p>...everything just works great. So, there would be a field named <code>user_name</code> if any of those annotations were honored, but they're clearly not.</p> <p><strong>SO</strong> my question is: Is there any way to decouple the tokens I use in the query from the name of the field? I'm looking for the ability to change the names of the fields without having to edit the queries by hand.</p> <p><em>NOTE:</em> I would sooner just use my SQL naming conventions in the Java classes than write the hideous amounts of XML by hand, so this has to be done with the annotations.</p>
 

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