Data e hora atual na formatação de data do Joda-Time para timestamp do mysql
Eu preciso importar a data e hora atuais em um campo de banco de dados MySQL cujo formato éTimeStamp. Do exame de dados de amostra, parece que o formato para o tipo de dados MySQL TimeStamp é "aaaa-mm-dd hh: mm: ss". estou usandoJoda-Time formatação no meu aplicativo de hibernação de primavera. Como faço para obter a data atual em um formato que será aceito pelo campo formatado do MySQL TimeStamp subjacente?
Aqui está o meu código atual, que não irá compilar porque o eclipse diz que .parseDateTime () requer um argumento de string e não um argumento DateTime:
public void setCreated(){
DateTime now = new org.joda.time.DateTime();
DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd hh:mm:ss");
created = fmt.parseDateTime(now);
System.out.println("'''''''''''''''''''''' created is: "+created);
}
A entidade que estou tentando persistir é definida da seguinte maneira:
@Entity
@Table(name = "documents")
public class Document {
@Id
@GeneratedValue
@Column(name="id")
private Integer id;
@ManyToOne
@JoinColumn(name = "client_id")
private Patient patient;
@ManyToOne
@JoinColumn(name = "type_id")
private DocumentType type;
@Column(name="name")
private String name;
@Column(name="description")
private String description;
@Column(name="filename")
private String filename;
@Column(name="content")
@Lob
private Blob content;
@Column(name="content_type")
private String contentType;
@Column(name = "created")
private DateTime created;
public Integer getId(){return id;}
public void setId(Integer i){id=i;}
protected void setPatient(Patient patient) {this.patient = patient;}
public Patient getPatient(){return this.patient;}
public void setType(DocumentType type) {this.type = type;}
public DocumentType getType() {return this.type;}
public String getName(){return name;}
public void setName(String nm){name=nm;}
public String getDescription(){return description;}
public void setDescription(String desc){description=desc;}
public String getFileName(){return filename;}
public void setFileName(String fn){filename=fn;}
public Blob getContent(){return content;}
public void setContent(Blob ct){content=ct;}
public String getContentType(){return contentType;}
public void setContentType(String ctype){contentType=ctype;}
public void setCreated(){
DateTime now = new org.joda.time.DateTime();
DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd hh:mm:ss");
created = fmt.parseDateTime(now);
System.out.println("''''''''''''''''''''''''''' created is: "+created);
}
public DateTime getCreated() {return this.created;}
@Override
public String toString() {return this.getName();}
public boolean isNew() {return (this.id == null);}
}
Como eu mudo o acima para que ele salve dados no formato correto para inserção em um campo MySQL TimeStamp?
EDITAR:Relacionado à sugestão de Sotirios, aqui estão partes relevantes para o meu pom.xml atual para fins de discussão:
<properties>
<jodatime-hibernate.version>1.3</jodatime-hibernate.version>
<jodatime-jsptags.version>1.1.1</jodatime-jsptags.version>
<jodatime.version>2.3</jodatime.version>
<jadira-usertype-core.version>3.1.0.CR8</jadira-usertype-core.version>
</properties>
<dependencies>
<dependency>
<groupId>org.jadira.usertype</groupId>
<artifactId>usertype.core</artifactId>
<version>${jadira-usertype-core.version}</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>${jodatime.version}</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time-hibernate</artifactId>
<version>${jodatime-hibernate.version}</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time-jsptags</artifactId>
<version>${jodatime-jsptags.version}</version>
</dependency>
</dependencies>