Monday, October 31, 2011

Re: Has anybody setup an owned Collection in RequestFactory? Does know how to set the ParentKey/ChildKey?

1. Well, the previous post has the link to the AppEngine JDO documentation on how to do that but it doesn't work in JPA the same way, more on that later in #4
2. You're right. I've been using gin for so long that I've forgotten about the setFactory method. The reason it works is not because of the class you pointed me too but this one here:

http://code.google.com/p/gwt-examples/source/browse/trunk/WalletInventory/src/com/gonevertical/client/app/ClientFactoryImpl.java

You're constructing your place tokenizers manually. You gain complete control of how you construct you tokenizers but at the expense of having to write the code yourself. In my code, I don't have anything implementing ApplicationPlaceHistoryMapper like you do, it's provided by gin.

However, now that i think about, gin should be able to do the same with ctor arguments provided the necessary Provider<T>s are in place

4. So you did:

@ElementCollection(targetClass=WalletItemData.class)
@CollectionTable(name="items")
@MapKey(name="key")
private List<WalletItemData> items;

What you're asking for is exactly:

@OneToMany(mappedBy="items") // mappedBy is ignored on AppEngine
private List<WalletItemData> items;

and in WalletItemData:
@ManyToOne
private WalletData parent;

but @ManyToOne isn't supported on AppEngine

and what I think you're looking for is something with automatic management of the child's relationship which is:

@OneToMany(mappedBy="items", cascade=ALL) // mappedBy is ignored on AppEngine
private List<WalletItemData> items;

Now, from inside a transaction, any new object you put in items will be persisted, any modified object will be updated and anything removed from the collection will be automatically deleted. You never need to call merge, persist or remove on an EntityManager for any of these operations since this collection is already managed and known to the entity manager.

If you absolutely need to know your parent from the child, outside of it being present in the parent's collection that is, you do it exactly the way you did it by setting and managing the parent key manually. The difference is the object type will be of the key type instead of the actual parent type.

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/Q2MGeA0tb9sJ.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment