Details

    • Type: Improvement Improvement
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Labels:
      None

      Description

      JPA currently only supports few Java types to be persisted, mostly generic types, Strings and Date. Since many applications would benefit from it, support for direct persistence of java.net.URL (as VARCHAR) and java.awt.Image (as BLOB) should be added. Both are commonly used in many applications and currently produce an overhead of manually written code when to be used in JPA entities.

      In addition (or as a replacement for the above), it would be great to have the possibility to map any not supported Java type to any kind of supported Java type, in analogy to the XmlAdapters used in JAXB marshall / unmarshall. This would relax the need for special support for Image and URL. As an example how this could work, please look at the following pseudo-code, which demonstrates how java.net.URL could get marshalled to a String at time of persisting it:

      @Column(name = "MY_SQL_FIELD_NAME"
      @JpaAdapter(UrlJpaAdapter.class)
      private URL someField;
      ...
      public class UrlJpaAdapter.class extends JpaAdapter<String, URL> {
      public URL unmarshal(String v) throws MalformedURLException

      { return new URL(v); }

      public String marshal(URL v)

      { return v.toString(); }

      }

        Activity

        mkarg created issue -
        Hide
        sinuhepop added a comment -

        I agree. This is a very common need and must be placed in JPA standard.

        But I think it will be too verbose to put always the same annotation n the same types. Maybe is better to use a TypeRegistry:

        TypeRegistry registry = entityManagerFactory.getTypeRegistry();
        registry.register(URL.class, new UrlJpaAdapter());

        Show
        sinuhepop added a comment - I agree. This is a very common need and must be placed in JPA standard. But I think it will be too verbose to put always the same annotation n the same types. Maybe is better to use a TypeRegistry: TypeRegistry registry = entityManagerFactory.getTypeRegistry(); registry.register(URL.class, new UrlJpaAdapter());
        ldemichiel made changes -
        Field Original Value New Value
        Assignee ldemichiel [ ldemichiel ]
        Hide
        neilstockton added a comment -

        Alternatively, allow JPA implementations to support as many field types as they want to, and provide method(s) on ProviderUtil that returns the types that are supported, or whether a type is supported.

        JPA could also just link in to the AttributeConverter facility, and a JPA implementation could find what converters are available in the CLASSPATH (and hence has support for them). Hence if a library provider wants their types automatically supported in all JPA implementations they just provide AttributeConverters ...

        Show
        neilstockton added a comment - Alternatively, allow JPA implementations to support as many field types as they want to, and provide method(s) on ProviderUtil that returns the types that are supported, or whether a type is supported. JPA could also just link in to the AttributeConverter facility, and a JPA implementation could find what converters are available in the CLASSPATH (and hence has support for them). Hence if a library provider wants their types automatically supported in all JPA implementations they just provide AttributeConverters ...

          People

          • Assignee:
            ldemichiel
            Reporter:
            mkarg
          • Votes:
            2 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated: