• 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 ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Copying JAXB properties to JPA entities

 
Ranch Hand
Posts: 658
2
Java
  • 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!
 
Bartender
Posts: 1845
10
  • 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:

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic