@Lob in JPA, what if the class is not Serializable

If you have

@Entity
public class Student {
    @Lob
    private static MyPictureClass picture;

and suppose you forgot to put Serializable to MyPictureClass, then guess what: there's no exception. You have to check the data in the DB.

Surprise no2:
Suppose MyPictureClassis a base abstract class and it is not Serializable. Suppose every inheriting class is Serializable. Then what happens? Well one thing's for sure: there wouldn't be an exception, but there wouldn't be any data in the DB (you'll get null). The runtime checks (in Hibernate) check the signature of the defining class I suppose, not the supplied class at runtime - and I would assume the opposite, because serialization works the opposite way. Maybe it's because Hibernate does some runtime bytecode modifications.

Leave a Reply

Your email address will not be published.

Notify me of followup comments via e-mail. You can also subscribe without commenting.

This site uses Akismet to reduce spam. Learn how your comment data is processed.