2

I'm trying to convert to list of hibernate objects to XML using JAXB. Are there any special considerations OR any reasons a list of hibernate objects with one to many relationship can't be converted?

1.) It seems like PersistentSet provided by Hibernate is not Serializable and hence, can't be converted by JAXB. I would probably would need to cast it to a "Serializable" set. Is this correct? If yes, how do I achieve it?

Edit 1. I'm going to write Set adapter class, similar to this example link. Will update my findings. http://www.objectpartners.com/2010/01/25/using-jpa-and-jaxb-annotations-in-the-same-object/

As mentioned below, there is no need to convert PersistentSet as it is serializable already.

Edit 2 (and Solution). Ok, I'm able to able to make it work.Thanks to Maven's Schemagen which gave the hint that 'java.sql.TimeStamp' is not compatible with JAXB. I wrote an adaptor which converts TimeStamp to Date.

Thanks everyone for guiding on this.

Prabhjot
  • 695
  • 3
  • 8
  • 21
  • JAXB implementations (MOXy, Metro, JaxMe, etc) do not require collection or domain classes to be serializable. – bdoughan Oct 17 '11 at 15:30

3 Answers3

5

PersistentBag and PersistenceSet, both are serializable. See http://docs.jboss.org/hibernate/core/3.2/api/org/hibernate/collection/PersistentSet.html and http://docs.jboss.org/hibernate/core/3.2/api/org/hibernate/collection/PersistentBag.html

Tarcísio Júnior
  • 1,239
  • 7
  • 15
1

Why don't you use hibernates xml store? It is much easier. http://docs.jboss.org/hibernate/core/3.3/reference/en/html/xml.html

Arash
  • 11,697
  • 14
  • 54
  • 81
0

I'm able to able to make it work.Thanks to Maven's Schemagen which gave the hint that 'java.sql.TimeStamp' is not compatible with JAXB. I wrote an adaptor which converts TimeStamp to Date.

Prabhjot
  • 695
  • 3
  • 8
  • 21