Mapping Eccezione con Hibernate 4.0, usertype 3.0.0.cr4 e Joda Time 2.1
Domanda
Attualmente sto cercando di persistere nel tempo di Joda in ibernazione usando usertype , ma continuo a ottenere il seguenteERRORE IN ECLIPSE.
(fallito.org.hirnate.mappingexception: impossibile determinare il tipo per: org.jadira.usertype.dateandtime.jsr310.persisttime.jsr310.persistlocaldatetime, alla tabella: modello_object, per colonne: [org.hibernate.mapping.Column (modificato_date_time)])
Il mio file XML è simile a questo
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="model" >
<class name="ModelObject" table="MODEL_OBJECT">
<id name="id" column="MODEL_ID" >
<generator class="native"></generator>
</id>
<property name="modifiedDateTime"
type="org.jadira.usertype.dateandtime.jsr310.PersistentLocalDateTime"
column="MODIFIED_DATE_TIME"/>
<property name="creationDateTime"
type="org.jadira.usertype.dateandtime.jsr310.PersistentLocalDateTime"
column="CREATION_DATE_TIME"/>
</class>
</hibernate-mapping>`
.
E il mio file Java sembra questo
package model;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import org.joda.time.LocalDateTime;
public abstract class ModelObject {
private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
private long id;
private LocalDateTime modifiedDateTime = new LocalDateTime ();
private LocalDateTime creationDateTime = new LocalDateTime ();
public Long getId(){
return id;
}
public void setId(Long id){
firePropertyChange("id", this.id, this.id = id);
}
public LocalDateTime getModifiedDateTime(){
return modifiedDateTime;
}
public void setModifiedDateTime(LocalDateTime modifiedDateTime) {
firePropertyChange("modifiedDateTime",
this.modifiedDateTime,
this.modifiedDateTime = modifiedDateTime);
}
public LocalDateTime getCreationDateTime(){
return creationDateTime;
}
public void setCreationDateTime(LocalDateTime creationDateTime){
firePropertyChange("creationDateTime",
this.creationDateTime,
this.creationDateTime = creationDateTime);
}
public void addPropertyChangeSupportListener(PropertyChangeListener listener){
changeSupport.addPropertyChangeListener(listener);
}
public void removePropertyChangeListener(PropertyChangeListener listener){
changeSupport.removePropertyChangeListener(listener);
}
public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener){
changeSupport.addPropertyChangeListener(propertyName, listener);
}
public void removePropertyChangeListener(String propertyName,
PropertyChangeListener listener){
changeSupport.addPropertyChangeListener(propertyName, listener);
}
protected void firePropertyChange(String propertyName, Object oldValue, Object newValue){
changeSupport.firePropertyChange(propertyName, oldValue, newValue);
}
}
.
Ho aggiunto usertype.spi-3.0.0.jar e usertype.core.3.0.0.cr3.jar al mio percorso di classe.
Non ho idea di cosa stia succedendo qui, allora Aiuta sarebbe molto apprezzato
Soluzione
Aggiungi file separato con i tipi personalizzati HBM
CustomTypes.hbm.xml
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.softcomputer.softlab.business.core">
<typedef name="localJodaDate"
class="org.jadira.usertype.dateandtime.jsr310.PersistentLocalDateTime" />
</hibernate-mapping>
.
Includi questo file alla tua mappatura
<mapping resource="CustomTypes.hbm.xml" />
. Altri suggerimenti
Il problema è che si sta utilizzando i tipi JSR 310 (per Threeten) anziché i tipi di tempo JODA.
cambia org.jadira.usertype.dateandtime.jsr310.persist.jsr310.persistlocaldatetime to org.jadira.Usertype.dateandtime.joda.persistLocaldateTime e il tuo problema dovrebbe essere risolto.
Saluti Chris