属性 映射的列数错误:
Property mapping has wrong number of columns:
我在 mysql 中使用休眠 4.3.7。我无法在 mysql 中坚持 joda tiem。当我使用这个注解时
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTimeWithZone"),它抛出这个异常
property mapping has wrong number of columns: car.modifiedDate type: org.jadira.usertype.dateandtime.joda.PersistentDateTimeWithZone
实体class:
@Entity
public class Car implements Serializable {
private static final long serialVersionUID = 1L;
/**
*/
@Column(name = "CAR_ID", nullable = false,length = 50)
@Basic(fetch = FetchType.EAGER)
@Id
@XmlElement
String carId;
/**
*/
@Column(name = "CAR_NAME", length = 50)
@Basic(fetch = FetchType.EAGER)
@XmlElement
String carName;
/**
*/
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTimeWithZone")
@Column(name = "DATE_CREATED")
@Basic(fetch = FetchType.EAGER)
@XmlElement
DateTime dateCreated;
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTimeWithZone")
@Column(name = "DATE_MODIFIED")
@Basic(fetch = FetchType.EAGER)
@XmlElement
DateTime modifiedDate;
/**
*/
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name="MCR_CAR_ID", nullable=false, insertable=false, updatable=false)
java.util.Set<MainCar> mainCar;
//setters and getters
}
Pom.xml
<dependency>
<groupId>org.jadira.usertype</groupId>
<artifactId>usertype.core</artifactId>
<version>3.0.0.CR1</version>
</dependency>
问题可能是您数据库中的 dateCreated
和 modifiedDate
列是 DateTime 类型,但您的代码保存为带区域的 DateTime。您能否尝试将 dateCreated
和 modifiedDate
类型编辑为 org.jadira.usertype.dateandtime.joda.PersistentDateTime
,如下所示:
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTime")
@Column(name = "DATE_CREATED")
@Basic(fetch = FetchType.EAGER)
@XmlElement
DateTime dateCreated;
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTime")
@Column(name = "DATE_MODIFIED")
@Basic(fetch = FetchType.EAGER)
@XmlElement
DateTime modifiedDate;
如果你想用 Zone 保存 DateTime,那么你必须将你的 @Type
修改为:
@Type(type="org.jadira.usertype.dateandtime.joda.PersistentDateTime",
parameters = { @Parameter(name = "databaseZone", value = "UTC"),
@Parameter(name = "javaZone", value = "jvm")})
@Column(name = "DATE_MODIFIED")
@Basic(fetch = FetchType.EAGER)
@XmlElement
DateTime modifiedDate;
我在 mysql 中使用休眠 4.3.7。我无法在 mysql 中坚持 joda tiem。当我使用这个注解时 @Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTimeWithZone"),它抛出这个异常
property mapping has wrong number of columns: car.modifiedDate type: org.jadira.usertype.dateandtime.joda.PersistentDateTimeWithZone
实体class:
@Entity
public class Car implements Serializable {
private static final long serialVersionUID = 1L;
/**
*/
@Column(name = "CAR_ID", nullable = false,length = 50)
@Basic(fetch = FetchType.EAGER)
@Id
@XmlElement
String carId;
/**
*/
@Column(name = "CAR_NAME", length = 50)
@Basic(fetch = FetchType.EAGER)
@XmlElement
String carName;
/**
*/
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTimeWithZone")
@Column(name = "DATE_CREATED")
@Basic(fetch = FetchType.EAGER)
@XmlElement
DateTime dateCreated;
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTimeWithZone")
@Column(name = "DATE_MODIFIED")
@Basic(fetch = FetchType.EAGER)
@XmlElement
DateTime modifiedDate;
/**
*/
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name="MCR_CAR_ID", nullable=false, insertable=false, updatable=false)
java.util.Set<MainCar> mainCar;
//setters and getters
}
Pom.xml
<dependency>
<groupId>org.jadira.usertype</groupId>
<artifactId>usertype.core</artifactId>
<version>3.0.0.CR1</version>
</dependency>
问题可能是您数据库中的 dateCreated
和 modifiedDate
列是 DateTime 类型,但您的代码保存为带区域的 DateTime。您能否尝试将 dateCreated
和 modifiedDate
类型编辑为 org.jadira.usertype.dateandtime.joda.PersistentDateTime
,如下所示:
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTime")
@Column(name = "DATE_CREATED")
@Basic(fetch = FetchType.EAGER)
@XmlElement
DateTime dateCreated;
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTime")
@Column(name = "DATE_MODIFIED")
@Basic(fetch = FetchType.EAGER)
@XmlElement
DateTime modifiedDate;
如果你想用 Zone 保存 DateTime,那么你必须将你的 @Type
修改为:
@Type(type="org.jadira.usertype.dateandtime.joda.PersistentDateTime",
parameters = { @Parameter(name = "databaseZone", value = "UTC"),
@Parameter(name = "javaZone", value = "jvm")})
@Column(name = "DATE_MODIFIED")
@Basic(fetch = FetchType.EAGER)
@XmlElement
DateTime modifiedDate;