This is what I have:
@XmlSchemaType(name = "dateTime")
@Column(name = "expiry-date", nullable = false)
protected XMLGregorianCalendar expiryDate;
The following exception is thrown:
org.hibernate.MappingException: Could not determine type for: javax.xml.datatype.XMLGregorianCalendar
Thank you
XMLGregorianCalendar
is not supported by JPA, you could use java.util.Date
or java.util.Calendar
(explained here).
Maybe you could take a look at the project Hyperjaxb3 (provides relational persistence for JAXB objects). Here it's explained how to deal with temporal properties:
Temporal properties (typed xsd:dateTime, xsd:date, xsd:time and so on) will be mapped as temporal JPA properties. Hyperjaxb3 will choose temporal type as TIMESTAMP, DATE or TIME depending on the XML Schema type of the temporal property. Temporal properties are typically mapped onto XMLGregorianCalendar which is not supported by JPA - and therefor must be wrapped:
<xs:element name="dateTime" type="xs:dateTime" minOccurs="0"/>
@XmlSchemaType(name = "dateTime")
protected XMLGregorianCalendar dateTime;
@Transient
public XMLGregorianCalendar getDateTime() {
return dateTime;
}
public void setDateTime(XMLGregorianCalendar value) {
this.dateTime = value;
}
@Basic
@Column(name = "DATETIMEITEM")
@Temporal(TemporalType.TIMESTAMP)
public Date getDateTimeItem() {
return XmlAdapterUtils.unmarshall(XMLGregorianCalendarAsDateTime.class, this.getDateTime());
}
public void setDateTimeItem(Date target) {
setDateTime(XmlAdapterUtils.marshall(XMLGregorianCalendarAsDateTime.class, target));
}
Another way would be to code your own solution, performing some transformations instead of trying to persist your JAXB object.