5

So I have the following situation:

@Entity
class Image {
  @Id
  @GeneratedValue
  private Long id;

  ....
}

@Entity
class ImageData implements Serializable {
  @Id
  @OneToOne
  private Image image;

  ....
}

This is all working fine, but why does ImageData need to be serializable? If it's not I get Exceptions that it needs to be serializable:

 org.hibernate.MappingException: composite-id class must implement Serializable:...

I know Identifier need to be serializable but why is it now the other way around?

suicide
  • 760
  • 4
  • 13
  • 20
  • That's strange - I was under the impression that *all* JPA entity classes need to be Serializable. – Mike Baranczak Apr 01 '11 at 18:55
  • 1
    if you don't have anything hibernate-specific, could you try, for a test, to replace it with eclipselink and see if this behaviour is consistent. If not - raise an issue. – Bozho Apr 03 '11 at 17:24
  • Possible duplicate of [Why composite-id class must implement Serializable?](https://stackoverflow.com/questions/9271835/why-composite-id-class-must-implement-serializable) – Federico Sierra Feb 18 '19 at 01:34

1 Answers1

0

There is a discussion about a similar topic on the Hibernate forums that should answer your question, have a look here

brent777
  • 3,369
  • 1
  • 26
  • 35
  • 1
    ok they are also saying that the class with the composite-id needs to be serializable but not why... – suicide Apr 01 '11 at 19:12