Précédent   Forum des professionnels en informatique > Java > Général Java > Persistance > JPA
JPA Forum d'entraide sur l'API de persistance JPA (Java Persistence API)
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 12/01/2012, 09h29   #1
Membre du Club
 
Avatar de POKOU
 
Homme
Inscription : décembre 2008
Messages : 86
Détails du profil
Informations personnelles :
Sexe : Homme
Âge : 50
Localisation : France, Finistère (Bretagne)

Informations forums :
Inscription : décembre 2008
Messages : 86
Points : 55
Points : 55
Par défaut Comment gérer une annotation sur un TimeStamp ?

Bonjour
Lors du remplissage par défaut d'un type TimeStamp dans le bean :
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
 
package beans;
 
import java.io.Serializable;
import java.util.*;
 
import javax.persistence.*;
 
import org.apache.tomcat.util.buf.TimeStamp;
 
@Entity
public class Ibanpay implements Serializable {
 
	private int ID;
	private String a8coibapay;
	private String a8liibapay;
	private int a8longiban;
	private String a8espasepa;
	private String a8usermain;
	private TimeStamp a8horomain;
 
	public Ibanpay()
	{	
	}
 
	public Ibanpay(String a8coibapay, String a8liibapay, int a8longiban, String a8espasepa,	String a8usermain)
	{
		setA8coibapay(a8coibapay);
		setA8liibapay(a8liibapay);
		setA8longiban(a8longiban);
		setA8espasepa(a8espasepa);
		setA8usermain(a8usermain);
		setA8horomain(new TimeStamp());
	}
...
ici les setters/getters
...	
	public void setA8horomain(TimeStamp a8horomain) {
		this.a8horomain = a8horomain;
	}
	@Temporal(TemporalType.TIMESTAMP)
	public TimeStamp getA8horomain() {
		return a8horomain;
	}
}
la JVM renvoie l'erreur
Citation:
...is org.hibernate.AnnotationException: @Temporal should be set on a java.util.Date or java.util.Calendar property: beans.Ibanpay.a8horomain
la table mysql est :
Code :
1
2
3
4
5
6
7
8
9
10
11
 
CREATE TABLE IF NOT EXISTS `ibanpay` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `a8coibapay` varchar(2) NOT NULL,
  `a8liibapay` varchar(30) NOT NULL,
  `a8longiban` int(2) NOT NULL,
  `a8espasepa` varchar(3) NOT NULL,
  `a8usermain` varchar(10) NOT NULL,
  `a8horomain` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`ID`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
pourriez vous m'aider ?
__________________
Je chasse le bug
POKOU est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 12/01/2012, 09h41   #2
Modérateur
 
Inscription : août 2006
Messages : 2 848
Détails du profil
Informations forums :
Inscription : août 2006
Messages : 2 848
Points : 2 950
Points : 2 950
Et si tu fais ce que te propose l'exception, c'est à dire de changer le type de a8horomain de Timestamp en Date dans ta classe Java mais en laissant l'annotation Timestamp
fr1man est déconnecté   Envoyer un message privé Réponse avec citation 10
Vieux 12/01/2012, 10h37   #3
Membre du Club
 
Avatar de POKOU
 
Homme
Inscription : décembre 2008
Messages : 86
Détails du profil
Informations personnelles :
Sexe : Homme
Âge : 50
Localisation : France, Finistère (Bretagne)

Informations forums :
Inscription : décembre 2008
Messages : 86
Points : 55
Points : 55
ça passe :
Citation:
...
INFO: Server startup in 3120 ms
Hibernate: insert into Ibanpay (a8coibapay, a8espasepa, a8horomain, a8liibapay, a8longiban, a8usermain) values (?, ?, ?, ?, ?, ?)
merci

le champ dans mySQL est rempli comme cela :
Citation:
INSERT INTO `ibanpay` (`ID`, `a8coibapay`, `a8liibapay`, `a8longiban`, `a8espasepa`, `a8usermain`, `a8horomain`) VALUES
(2, 'FR', 'FRANCE', 27, 'OUI', 'TOTOTO', '2012-01-12 10:33:14');
le timestamp sur un iseries est comme ça :
Citation:
A8COIBAPAY A8LIIBAPAY A8LONGIBAN A8ESPASEPA A8USERMAIN A8HOROMAIN
---------- ------------------------------ ---------- ---------- ---------- --------------------------
FR France 27 OUI TOTOTO 2012-01-09 14:52:03.196646
AD Andorre 24 OUI TOTOTO 2012-01-09 14:57:37.641284
je continue à chercher
__________________
Je chasse le bug
POKOU est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 12/01/2012, 10h40   #4
Modérateur
 
Inscription : août 2006
Messages : 2 848
Détails du profil
Informations forums :
Inscription : août 2006
Messages : 2 848
Points : 2 950
Points : 2 950
N'oublie pas le tag résolu.
fr1man est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 23h09.


 
 
 
 
Partenaires

Hébergement Web