asma
asma

Reputation: 147

Property mapping has wrong number of columns:

I'm using hibernate 4.3.7 with mysql. I'm unable to persist joda tiem in mysql. When I use this annotation @Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTimeWithZone"), it throws this exception

property mapping has wrong number of columns: car.modifiedDate type: org.jadira.usertype.dateandtime.joda.PersistentDateTimeWithZone

Entity 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>

Upvotes: 3

Views: 7441

Answers (1)

Arpit Aggarwal
Arpit Aggarwal

Reputation: 29276

The problem might be dateCreated and modifiedDate column in your Database is of type DateTime but your code is saving as DateTime with zone. Can you try editing the dateCreated and modifiedDate type to org.jadira.usertype.dateandtime.joda.PersistentDateTime as below:

@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;

And if you want to save DateTime with Zone, then you have to modify your @Type as:

  @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;

Upvotes: 1

Related Questions