• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

Copying JAXB properties to JPA entities

Ranch Hand
Posts: 658
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am having a requirement where I need to read an data XML file and then send the data to the Oracle DataBase. For this, I am using JAXB to read the XML file and JPA-Hibernate to persist data in DB. By unmarshalling the XML file using JAXB, I got the complete data in a bean, then I copied the Bean's property to the JPA entity bean using Apache BeanUtils and the persists the data using Hibernate. Below is the code:

But while copying the properties from JAXB to JPA entity I am facing an error : org.apache.commons.beanutils.ConversionException: DateConverter does not support default String to 'Date' conversion. Which clearly explains that there is some property in JAXB which is of type 'String' but the same name property is of type 'Date' in JPA entity class. But I don't know how can I handle this situation, as I cannot verify the list of property because there are 900+ property variables in JAXB class.
How can I handle this situation? suggestions please!
Posts: 1845
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you know the valid date format(s) that you will be receiving in the XML?
At some point you need to convert from a String into a Date.

You can do this in the JAXB layer, or with the BeanUtils specifying date formats for the converter.
The important segment:

Example test code below:

Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic