Pergunta

Atualmente, estou tentando manter Joda Time no Hibernate usando usertype, mas eu continuo recebendo o seguinte erro no eclipse.

Error Message

(falha.org.o hibernate.MappingException:Não foi possível determinar o tipo para:org.jadira.usertype.dateandtime.jsr310.PersistentLocalDateTime, à mesa:MODEL_OBJECT, para colunas:[org.o hibernate.mapeamento.Coluna(MODIFIED_DATE_TIME)])

meu arquivo xml parecido com este

<?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 o meu java arquivo se parece com isto

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

}

Eu adicionei usertype.spi-3.0.0.jar e usertype.core.3.0.0.CR3.jar para o meu caminho de classe.

Eu não tenho nenhuma idéia o que está acontecendo aqui para ajuda seria muito apreciada

Foi útil?

Solução

Adicionar arquivo separado com a HBM tipos personalizados
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>  

incluir esse arquivo para o seu mapeamento

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

Outras dicas

O problema é que você está usando a JSR 310 tipos (por threeten) ao invés do Joda tipos de Tempo.

Alterar org.jadira.usertype.dateandtime.jsr310.PersistentLocalDateTime para org.jadira.usertype.dateandtime.joda.PersistentLocalDateTime e o problema deverá ser resolvido.

Atenciosamente Chris

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top