Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Hibernate and XmlGregorianCalendar

Posted on 2011-03-11
Medium Priority
Last Modified: 2013-11-13

I'm using JAXB and also Hibernate. But, I got a problem with Hibernate and XmlGregorianCalendar.

Below is a part of my class witch works with JAXB.
public class test
    @XmlElement(name = "Created", required = true)
    protected XMLGregorianCalendar created;
    @XmlElement(name = "CreatedBy", required = true)
    protected String createdBy;
    @XmlElement(name = "Changed", required = true)
    protected XMLGregorianCalendar changed;
    @XmlElement(name = "ChangedBy", required = true)
    protected String changedBy;

Open in new window

The problem I got now is that I don't know what to do to get it to work with Hibernate and how to create a mapping file to this class when using XMLGregorianCalendar. If I change XMLGregorianCalendar to java.util.Date I get it to work with Hibernate but not with JAXB.

Is there any solution to this?

Question by:freeOne
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
LVL 92

Expert Comment

ID: 35107812
I'd suggest using different beans for jaxb and hibernate, specifying the mapping for both in one class gets messy.
And you can get your jaxb class automatically generated from your xml schema

Author Comment

ID: 35107880
Which ones do you recomend?
LVL 92

Expert Comment

ID: 35107942
I generally map the actual bean with hibernate
and generate a seperate bean (from the xsd) for exporting/importing from xml.
Then you just need a utility method to convert between the two when you need to go to/from xml
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.


Author Comment

ID: 35108077
Is it possible to get an example?

Author Comment

ID: 35108117
LVL 92

Accepted Solution

objects earned 2000 total points
ID: 35112963
> Is it somthing like this you meean?

yes, though we usually start with an xsd schema, and generate the classes directly from that

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is about my first experience with programming Arduino.
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Starting up a Project
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question