users@glassfish.java.net

Re: JPA questions

From: <glassfish_at_javadesktop.org>
Date: Tue, 15 Jan 2008 13:22:27 PST

Hi Ivan,

1, 2. Collections of primitives are beyond JPA spec, so you either need to look at vendor's extensions or work around it. If you choose the former, you need to use relationships with Collection<Keyword> keywords, and you can't use a secondary table because it means a one-to-one association with the primary table (even though it's not a relationship in that case).
You do not need to map all columns of the KEYWORDS table to the fields in a Keyword entity (unless you use native queries that do 'select *'), but the entity needs to have an Id. Usually JPA providers don't verify that the Id is mapped to a PK column (they hope you did it right ;)).

3. Self-referenced relationships are supported, but as with any relationships, if there is no related instance, the expectation is that the FK value is null, i.e. not set. So you are again looking for the JPA provider extension. TopLink has a customiser option that you can add to your application which will allow you to convert 0 to null. See http://forums.java.net/jive/thread.jspa?threadID=19246 for a similar solution.

HTH,
-marina
[Message sent by forum member 'mvatkina' (mvatkina)]

http://forums.java.net/jive/thread.jspa?messageID=254073