openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "catalina wei" <catalina....@gmail.com>
Subject [DISCUSS] Mapping persistent field to Database back-end XML columns
Date Wed, 09 May 2007 22:06:21 GMT
[DISCUSS 1]:
Many database systems now have support for XML types which includes DB2 v9.1,
DB2 zOS v9, Oracle 10g, and SQLServer 2005.
Tables may contain XML columns where you can store XML documents.
What is OpenJPA's position of supporting the XML columns ?
The current mapping choices for XML columns are:
1.  Java String
2.  Java Byte array

Can openjpa provide other mapping options for XML columns?
  [DISCUSS 2]:
Should XML mapping function be considered a new feature ?

[DISCUSS 3]:
My second part of the discussion is related to an XML Value Handler that I
implemented by extending AbstractValueHandler as described under Mapping
Extensions of OpenJPA developer'sGguide. My implementation has dependency on
JAXB bindings.
This XmlValueHandler is annotated on @Strategy("XmlValueHandler") for the
field that maps to XML column.

My XmlValueHandler worked fine for inserts and deletes, but not for updates.

The problem in updates is that the value passed to toDataStoreValue() is
wrapped in a Proxy, I can't get the original Class for the value object.
val.getClass() is returning the Proxy wrapped class, not the original class.

 To workaround it, I have to use some klugy code - checking if val is a
proxy or not.

Is there a better way to find out the actual class from a proxy ?


    public Object toDataStoreValue(ValueMapping vm, Object val,
        JDBCStore store) {
        // check for null value.
        if (val==null) return null;
        try {
            //JAXBContext jc = JAXBContext.newInstance(val.getClass());
            JAXBContext jc = JAXBContext.newInstance(
                    // on update val is a proxy, that can not be marshalled.
                    // use the declared type in this case.
                    (val.getClass().getName().contains("$proxy"))
                             ? vm.getDeclaredType()
                             : val.getClass());
            Marshaller m = jc.createMarshaller();
            Writer result = new StringWriter();
            m.marshal( val, result );
            return result.toString();
        }


 Catalina

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message