Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8814355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:06:05+00:00 2026-06-14T04:06:05+00:00

How to declare id field as Key as encoded String in JPA entity (not

  • 0

How to declare id field as “Key as encoded String” in JPA entity (not JDO) for usage in GAE Datastore? You can find example for JDO, but not for JPA.

Can’t declare id fields as Long as entity is used in child-parent relations.

So, my entity is like this:

@Entity
public class EntityClass {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true")
    private String id;

So, it uses both JPA and JDO annotations.

So, while trying to persist entity object i’m getting an exception:

Cannot have a null primary key field if the field is unencoded and of type String. Please provide a value or, if you want the datastore to generate an id on your behalf, change the type of the field to Long.
org.datanucleus.store.appengine.FatalNucleusUserException: Invalid primary key for name.xxx.tips.db.User. Cannot have a null primary key field if the field is unencoded and of type String. Please provide a value or, if you want the datastore to generate an id on your behalf, change the type of the field to Long.

Full Stacktrace:
Cannot have a null primary key field if the field is unencoded and of type String. Please provide a value or, if you want the datastore to generate an id on your behalf, change the type of the field to Long.
org.datanucleus.store.appengine.FatalNucleusUserException: Invalid primary key for name.xxx.tips.db.User. Cannot have a null primary key field if the field is unencoded and of type String. Please provide a value or, if you want the datastore to generate an id on your behalf, change the type of the field to Long.
at org.datanucleus.store.appengine.DatastoreFieldManager.storeStringPKField(DatastoreFieldManager.java:540)
at org.datanucleus.store.appengine.DatastoreFieldManager.storeStringField(DatastoreFieldManager.java:460)
at org.datanucleus.state.AbstractStateManager.providedStringField(AbstractStateManager.java:1023)
at name.xxx.tips.db.User.jdoProvideField(User.java)
at name.xxx.tips.db.User.jdoProvideFields(User.java)
at org.datanucleus.state.JDOStateManagerImpl.provideFields(JDOStateManagerImpl.java:2715)
at org.datanucleus.store.appengine.DatastorePersistenceHandler.insertPreProcess(DatastorePersistenceHandler.java:357)
at org.datanucleus.store.appengine.DatastorePersistenceHandler.insertObjects(DatastorePersistenceHandler.java:267)
at org.datanucleus.store.appengine.DatastorePersistenceHandler.insertObject(DatastorePersistenceHandler.java:256)
at org.datanucleus.state.JDOStateManagerImpl.internalMakePersistent(JDOStateManagerImpl.java:3185)
at org.datanucleus.state.JDOStateManagerImpl.flush(JDOStateManagerImpl.java:4513)
at org.datanucleus.state.JDOStateManagerImpl.getExternalObjectId(JDOStateManagerImpl.java:1334)
at org.datanucleus.state.JDOStateManagerImpl.getObjectId(JDOStateManagerImpl.java:1234)
at name.xxx.tips.db.User.jdoGetObjectId(User.java)
at org.datanucleus.jpa.JPAAdapter.getIdForObject(JPAAdapter.java:266)
at org.datanucleus.ObjectManagerImpl.exists(ObjectManagerImpl.java:1953)
at org.datanucleus.jpa.EntityManagerImpl.refresh(EntityManagerImpl.java:469)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T04:06:07+00:00Added an answer on June 14, 2026 at 4:06 am

    Why are you using JDO annotations if using JPA ?
    The annotation to use for extensions with JPA is

    org.datanucleus.api.jpa.annotations.Extension
    

    as shown here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do I declare a condition for a field key value. I have a
In Java, is it possible to declare a field/variable whose type is multiple interfaces?
5 import java.util.*; 6 7 class Matrix { 8 // declare the member field
I'm evaluating selfish and am wondering how I can declare private methods/fields?
I can't figure out how to declare a OneToOne unidirectional relationship. The TripDeparture model
How can I search my sql database for a table that contains a field
The following code will return select $f/field/text() from table1 declare @x xml = '<meta><field>Column1</field></meta>';
I have a field declared as a Map<MyEnum, String> , which is audited. When
I've declared a field in my INNODB/MySQL table as VARCHAR(255) CHARACTER SET utf8 NOT
I declared a field: WriteableBitmap colorBitmap; Then I created a simple thread which does

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.