users@glassfish.java.net

Re: RE: basic jpa collection question

From: <glassfish_at_javadesktop.org>
Date: Fri, 09 Mar 2007 08:52:01 PST

Here is an example of how you would add the mapping using a Session Customizer.

[u]Persistence.xml entry:[/u]
        <property name="toplink.session.customizer" value="mypackage.MyInvalidationCustomizer"/>

[u]Customizer Class :[/u]
package mypackage;
import oracle.toplink.essentials.sessions.Session;
import oracle.toplink.essentials.mappings.DirectCollectionMapping;
import oracle.toplink.descriptors.RelationalDescriptor;

/**
 * PUBLIC:
 * This interface is to allow extra customization on a TopLink Session
 */
public class DirectCollectionCustomizer extends SessionCustomizer {
    public void customize(Session session) throws Exception {
        RelationalDescriptor descriptor = (RelationalDescriptor)session.getDescriptor(Entity.class);
        //remove the JPA default mapping
        descriptor.removeMappingForAttributeName("propertyName);
        
        DirectCollectionMapping mapping = new DirectCollectionMapping();
        mapping.setAttributeName(“propertyName”);
        mapping.dontUseIndirection();
        mapping.useCollectionClass(Set.class);
        mapping.setReferenceTableName(“TABLENAME”);
        mapping.setDirectFieldName(“TABLENAME.VALUECOLUMN”);
        mapping.addReferenceKeyFieldName(“TABLENAME.FKCOLUMN”);
        descriptor.addMapping(mapping);
    }
}


Although I am just speculating, this mapping type did not make it into the JPA specification because of time constraints. I would expect to see it in a future version of the Spec.

--Gordon
[Message sent by forum member 'gyorke' (gyorke)]

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