two entities: Post and Category,  i user jpa.

@Entity
public class Post implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Key id;
    @ManyToOne
    private Category category;
}

@Entity
public class Category implements Serializable, Cloneable{
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    @OneToMany(mappedBy="category")
    private List<Post> posts;
}

i user jpa.

when i persist an entity int a servlet like this

        Long categoryId = Long.parseLong(request.getParameter
("category"));

        Category c = categoryDao.get(categoryId);

        Post p = new Post();
        p.setCategory(c);

        postDao.save(p);

it is all right, i can success persist the entity every time


but when i want to user jcache to cache the categoy for the next use,
like this

        Long categoryId = Long.parseLong(request.getParameter
("category"));

        Cache cache = StaticRes.getCache();
        Category c;
        if (cache.containsKey(categoryId)) {
            c = (Category) cache.get(categoryId);
        } else {
            c = categoryDao.get(categoryId);
            cache.put(categoryId, c);
        }

        Post p = new Post();
        p.setCategory(c);
        postDao.save(p);

first i persist a entity post with a category so the category was in
cache, then i try to persist post with the same category and i think
it will get the category object from the cache. the problem is : the
second post i want to persist replace the first post in the
datastore.  that is if i try to persist a post with the category in
cache , the post will replace the first post with the same category
which got from the dao, and not a new in the datastore.i cant find how
it goes wrong.



my english is not very well, hope you can understand



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-java@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to