#141 Model classes should implement serializable

Release
open-invalid
General (64)
5
2012-01-14
2012-01-13
No

Currently it is very hard to store ical model properties like Recur or ExDate in a database using JPA since they are not serializable. It would be much easier if they provided this capability.

Discussion

  • Ben Fortuna

    Ben Fortuna - 2012-01-14

    Hi Robert,

    Most of the model classes do implement Serializable, however if you have specific examples where this doesn't work please provide more details (note that Recur and ExDate do both implement Serializable).

    regards,
    ben

     
  • Ben Fortuna

    Ben Fortuna - 2012-01-14
    • labels: --> General
    • milestone: --> Release
    • assigned_to: nobody --> fortuna
    • status: open --> pending-invalid
     
  • Robert Wetzold

    Robert Wetzold - 2012-01-14
    • status: pending-invalid --> open-invalid
     
  • Robert Wetzold

    Robert Wetzold - 2012-01-14

    I debugged some more and indeed Recur and DateList are serializable, but one has to include a dependency to [1] to make it work. JPA still fails though with a validation exception stating that the attribute "type" of DateList is not serializable [2].

    [1] edu.emory.mathcs.backport.java.util.concurrent
    [2] Exception Description: The type [class net.fortuna.ical4j.model.DateList] for the attribute [excludeDates] on the entity class [class com.company.MyEntity] is not a valid type for a serialized mapping. The attribute type must implement the Serializable interface.

     
  • Ben Fortuna

    Ben Fortuna - 2012-01-14

    Note that I have added a new test for verifying model objects serialize correctly (ModelSerializationSpec). If you can provide a specific example calendar I can add it to the test to see what the problem is.

    regards,
    ben

     
  • Robert Wetzold

    Robert Wetzold - 2012-01-14

    All I actually did was to create a new Entity class and as soon as JPA loads the class it throws the validation error. Example Class:

    @Entity
    public class MyEntity {
    @Id
    @GeneratedValue(strategy = GenerationType.TABLE)
    private long id;
    private DateList excludeDates = new DateList();
    ....
    }

    Does that help you to construct a test case? I wouldn't know right now what else to provide.

    Regards, Robert

     
  • Ben Fortuna

    Ben Fortuna - 2012-01-14

    Ok, after a quick search I think you need to add an @Lob annotation to a serializable object to store it as a BLOB. eg:

    @Entity
    public class MyEntity {
    @Id
    @GeneratedValue(strategy = GenerationType.TABLE)
    private long id;

    @Lob
    private DateList excludeDates = new DateList();
    ....
    }

    See this article for more details:

    http://en.wikibooks.org/wiki/Java_Persistence/Basic_Attributes#LOBs.2C_BLOBs.2C_CLOBs_and_Serialization

    Note that I haven't tested this myself.

    regards,
    ben

     
  • Robert Wetzold

    Robert Wetzold - 2012-01-14

    Thanks for the quick reply. I tried it but there's still a very similar sounding exception [1]. For some reason it does have a problem with the DateList.type attribute. I checked the class files and up the hierarchy it implements serializable so I couldn't find an obvious reason for the error but I am also not a serialization expert. Do you have a JPA project where you can quickly register a new entity class? My setup is a bit too big here to furnish a small example from. I will consult our persistence colleagues on Monday if they have an idea what might cause this.

    Exception Description: The type [class net.fortuna.ical4j.model.DateList] for the attribute [excludeDates] on the entity class [class com.Myentity] is not a valid type for a lob mapping. For a lob of type BLOB, the attribute must be defined as a java.sql.Blob, byte[], Byte[] or a Serializable type. For a lob of type CLOB, the attribute must be defined as a java.sql.Clob, char[], Character[] or String type.

     

Log in to post a comment.