Solved

Hibernate and XmlGregorianCalendar

Posted on 2011-03-11
7
1,614 Views
Last Modified: 2013-11-13
Hi,

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?

0
Comment
Question by:freeOne
  • 3
  • 3
7 Comments
 
LVL 92

Expert Comment

by:objects
Comment Utility
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
0
 

Author Comment

by:freeOne
Comment Utility
Which ones do you recomend?
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
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
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:freeOne
Comment Utility
Is it possible to get an example?
0
 

Author Comment

by:freeOne
Comment Utility
0
 
LVL 20

Expert Comment

by:Sathish David Kumar N
Comment Utility
0
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
Comment Utility
> Is it somthing like this you meean?

yes, though we usually start with an xsd schema, and generate the classes directly from that
http://publib.boulder.ibm.com/infocenter/wasinfo/v7r0/index.jsp?topic=/com.ibm.websphere.express.doc/info/exp/ae/twbs_jaxbschema2java.html
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article will show, step by step, how to integrate R code into a R Sweave document
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
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…

728 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now