Spring Data Commons
  1. Spring Data Commons
  2. DATACMNS-180

Java transient fields should not be considered transient for persistence

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.3.1, 1.4 M1
    • Component/s: Mapping metadata
    • Labels:
      None

      Description

      AbstractPersistentProperty treats plain transient fields as transient an thus those fields will not end up being persisted which is probably not in line with what one wants to achieve by making the field transient.

      Although the Java specification says transient expresses a property shall not be serialized we actually have to as they are usually reconstituated in a readObject(…) method we cannot call and thus would not recreate the object in a state it was before persisting.

        Activity

        Hide
        Russell Allen added a comment -

        I realize this is closed, but... well, here is a case where this change had a negative impact.

        I am persisting a sub-class of application event (org.springframework.context.ApplicationEvent). ApplicationEvent extends java.util.EventObject which contains a transient 'source' property (type Object).

        Before DATACMNS-180, the event's source was dropped and all was well. With the latest version though, spring-data attempts to persist a complex object from the source property (in my particular case) and fails.

        What are my options in this case? The offending property is out of my control (I can't add @Transient to a java.util class.) Is there a way to specify properties to ignore without annotations?

        Show
        Russell Allen added a comment - I realize this is closed, but... well, here is a case where this change had a negative impact. I am persisting a sub-class of application event (org.springframework.context.ApplicationEvent). ApplicationEvent extends java.util.EventObject which contains a transient 'source' property (type Object). Before DATACMNS-180 , the event's source was dropped and all was well. With the latest version though, spring-data attempts to persist a complex object from the source property (in my particular case) and fails. What are my options in this case? The offending property is out of my control (I can't add @Transient to a java.util class.) Is there a way to specify properties to ignore without annotations?
        Hide
        Oliver Gierke added a comment -

        Have you tried overriding the getter and annotating this with @Transient?

        Show
        Oliver Gierke added a comment - Have you tried overriding the getter and annotating this with @Transient ?
        Hide
        Russell Allen added a comment -

        Ah, that worked!

        Thank you.

        Show
        Russell Allen added a comment - Ah, that worked! Thank you.

          People

          • Assignee:
            Oliver Gierke
            Reporter:
            Oliver Gierke
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: