2012-09-30 25 views
1

我目前正試圖堅持使用usertype在休眠喬達時間,但我一直在eclipse中得到以下錯誤。與Hibernate 4.0,UserType 3.0.0.CR4和Joda時間2.1映射例外

Error Message

(failed.org.hibernate.MappingException:無法確定類型:org.jadira.usertype.dateandtime.jsr310.PersistentLocalDateTime,在表:MODEL_OBJECT,對於列:[org.hibernate.mapping .COLUMN(MODIFIED_DATE_TIME)])

我的XML文件看起來像這樣

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

和我的java文件看起來像這樣

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

} 

我已將usertype.spi-3.0.0.jar和usertype.core.3.0.0.CR3.jar添加到我的課程路徑中。

我不知道是怎麼回事就在這裏這樣有利於將不勝感激

回答

1

添加單獨的文件與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> 

包含這個文件到你的映射

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

感謝您的回覆,但我仍然遇到與以前一樣的錯誤。我已經更新了我的問題,以便在eclipse中包含錯誤的打印屏幕,如果有任何幫助的話。感謝您的時間。 – user1239299

+0

看來,如果我做一個自定義類型,我可以完全跳過UserType,這似乎解決了我的錯誤。 user1239299

0

問題是,您正在使用JSR 310類型(for threeten)而不是Jo da時間類型。

將org.jadira.usertype.dateandtime.jsr310.PersistentLocalDateTime更改爲org.jadira.usertype.dateandtime.joda.PersistentLocalDateTime並解決您的問題。

Regards Chris