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

  • SEARCH
  • Home
  • 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 7619585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:43:26+00:00 2026-05-31T03:43:26+00:00

I have an entity like this: @Entity @XmlRootElement public class Article { @Id @GeneratedValue(strategy

  • 0

I have an entity like this:

@Entity
@XmlRootElement
public class Article {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private com.google.appengine.api.datastore.Key key;
private String content;
private String title;
private Date created; 
private Date lastUpdate;

private boolean isActive;

   /* public getter and setters */
}

Now I have a rest webserivce which returns the articles:

@SuppressWarnings({ "unchecked", "unused" })
@GET
@Path("/{user}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public List<Article> getArtilceListByUser(@PathParam("user") String userName) {

    List<Article> articles = null;
    EntityManager em = EMF.get().createEntityManager();
    try {
        articles = (List<Article>) em.createQuery("SELECT FROM Article WHERE createdBy = :user AND isActive = true")
                    .setParameter("user", userName)
                    .getResultList();
        // lazy load is activated, but em is closed (find a better solution)
        for (Article article : articles) ;

    } finally {
        em.close();
    }

    return articles;
}

The problem is, that the object of com.google.appengine.api.datastore.Key cannot get serialized to json or xml, but I need the id of the articles… So have I to use a long-type for the id or to add an extra field, which wraps the key? Do you have better solutions for this problem?

  • 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-05-31T03:43:28+00:00Added an answer on May 31, 2026 at 3:43 am

    com.google.appengine.api.datastore.KeyFactory.keyToString

    and then

    com.google.appengine.api.datastore.KeyFactory.stringToKey

    These create and consume “websafe” keys for just this purpose.

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

Sidebar

Related Questions

i have an entity like this: public class Account{ private String code; @ManyToOne private
I have a Person and an Organisation Entity: Person looks like this: public class
Assuming I have an Entity Framework 4.2 class like this: class Company { public
I have an entity that looks like this: public partial class MemberTank { public
Let's say I have an entity that looks like this: public class Album() {
I have an entity like this: public class Person { public string Name {
I have an Entity object, Item, that looks like this.. public class Item() {
If I have an entity in RIA services like this, [EnableClientAccess] public class ShapeEntity
I'm using app engine datastore so I have entity like this. @PersistenceCapable public class
I have an Entity like this: public class Category { public int classid {get;set;}

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.