Pregunta

Actualmente estoy tratando de persistir la hora de Joda en Hibernate usando ustype , pero sigo obteniendo lo siguienteError en Eclipse.

Mensaje de error

(fallido.org.hibernate.mappingException: no se pudo determinar el tipo para: org.jadira.usertype.dateandtime.jsr310.peristentlocaldateTime, en la tabla: model_object, para columnas: [org.hibernate.mapping.column (modificado_date_time)])

Mi archivo XML se ve así

<?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>`

y mi archivo java se ve así

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);
}

}

He añadido a usertype.spi-3.0.0.jar y usertype.core.3.0.0.cr3.jar a mi ruta de clase.

No tengo idea de lo que está pasando aquí, así que la ayuda sería muy apreciada

¿Fue útil?

Solución

Añadir archivo separado con tipos personalizados 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>  

Incluya este archivo a su asignación

  <mapping resource="CustomTypes.hbm.xml" />

Otros consejos

El problema es que está utilizando los tipos JSR 310 (para Threeten) en lugar de los tipos de tiempo JODA.

Cambiar org.jadira.usertype.dateandtime.jsr310.peristentlocaldateTime a org.jadira.usertype.dateandtime.joda.persistentlocaldaldetime y su problema debe resolverse.

Saludos a Chris

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top