users@glassfish.java.net

Re: Casting field to another type before query executes?

From: <glassfish_at_javadesktop.org>
Date: Fri, 07 Dec 2007 08:09:26 PST

You can use a converter in TopLink to convert the special date format to a regular date in the object model. The interface your converter should implement is : oracle.toplink.essentials.mappings.converters.Converter

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

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

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

/**
* PUBLIC:
* This interface is to allow extra customization on a TopLink Session
*/
public class ConverterCustomizer extends SessionCustomizer {
    public void customize(Session session) throws Exception {
        RelationalDescriptor descriptor = session.getDescriptor(<class to take converter>);
        DirectToFieldMapping mapping = (DirectToFieldMapping)descriptor.getMappingForAttributeName(<mapping to be converted>);
        mapping.addConverter(new YourConverter);
    }
}
[/code]
[Message sent by forum member 'gyorke' (gyorke)]

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