gpt4 book ai didi

java - Hibernate 4.0、UserType 3.0.0.CR4 和 Joda Time 2.1 的映射异常

转载 作者:太空宇宙 更新时间:2023-11-04 08:02:20 25 4
gpt4 key购买 nike

我目前正在尝试使用 usertype 在 Hibernate 中保留 Joda Time ,但我在 eclipse 中不断收到以下错误。

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 添加到我的类路径中。

我不知道这里发生了什么,所以我们将不胜感激

最佳答案

使用 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" />

关于java - Hibernate 4.0、UserType 3.0.0.CR4 和 Joda Time 2.1 的映射异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12658521/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com