0
I own these 3 classes as a model.
Object:
import java.io.Serializable;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@Entity
@Table(name="objeto")
@Inheritance(strategy=InheritanceType.JOINED)
public class Objeto implements Serializable{
private static final long serialVersionUID = 1L;
@Getter
@Setter
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Getter
@Setter
@XmlElement
@Column(nullable = false, length = 13, unique = true)
private String numero;
@Getter
@Setter
@XmlElement
@Column
private String sigla;
@Getter
@Setter
@XmlElement
@Column
private String nome;
@Getter
@Setter
@XmlElement
@Column
private String categoria;
@Getter
@Setter
@XmlElement(name = "evento")
@OneToMany(mappedBy = "objeto", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
private List<Evento> eventos;
@Getter
@Setter
@XmlElement
@Column
private String erro;
}
Event:
import java.io.Serializable;
import java.time.LocalDate;
import java.time.LocalTime;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@EqualsAndHashCode
@NoArgsConstructor
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@Entity
@Table(name = "evento")
public class Evento implements Serializable{
private static final long serialVersionUID = 1L;
@Getter
@Setter
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Getter
@Setter
@XmlElement
@Column
private String tipo;
@Getter
@Setter
@XmlElement
@Column
private Integer status;
@Getter
@Setter
@XmlTransient
@Column
private LocalDate data;
@Getter
@Setter
@XmlElement(name="data")
private String dataAux;
@Getter
@Setter
@XmlTransient
@Column
private LocalTime hora;
@Getter
@Setter
@XmlElement(name="hora")
private String horaAux;
@Getter
@Setter
@XmlElement
@Column
private String descricao;
@Getter
@Setter
@XmlElement
@Column
private String recebedor;
@Getter
@Setter
@XmlElement
@Column
private String documento;
@Getter
@Setter
@XmlElement
@Column
private String comentario;
@Getter
@Setter
@XmlElement
@Column
private String local;
@Getter
@Setter
@XmlElement
@Column
private Integer codigo;
@Getter
@Setter
@XmlElement
@Column
private String cidade;
@Getter
@Setter
@XmlElement
@Column
private String uf;
@Getter
@Setter
@XmlElement
@OneToOne(mappedBy="evento",cascade = CascadeType.ALL)
private Destino destino;
@Getter
@Setter
@ManyToOne(cascade=CascadeType.ALL)
@JoinColumn(name = "objeto_id", referencedColumnName = "id")
private Objeto objeto;
}
And Destiny:
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@AllArgsConstructor
@EqualsAndHashCode
@NoArgsConstructor
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@Entity
@Table(name = "destino")
public class Destino implements Serializable{
private static final long serialVersionUID = 1L;
@Getter
@Setter
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Getter
@Setter
@XmlElement
@Column
private String local;
@Getter
@Setter
@XmlElement
@Column
private Integer codigo;
@Getter
@Setter
@XmlElement
@Column
private String cidade;
@Getter
@Setter
@XmlElement
@Column
private String uf;
@Getter
@Setter
@OneToOne
@JoinColumn(name = "evento_id")
private Evento evento;
}
In the Event class I have the time attribute which is a LocalTime
, i fill this field through this method:
public static LocalTime stringToTime(String src) {
final DateTimeFormatter fHora = DateTimeFormatter.ofPattern("HH:mm");
final LocalTime hora = LocalTime.parse(src, fHora);
return hora;
}
Let’s say you stayed with the hour 12:00.
My kind of persistence:
public class ServiceBase {
@PersistenceContext(unitName = "tracker")
protected EntityManager em;
public void insert(Objeto objeto) {
this.em.persist(objeto);
}
}
Until then it’s okay, to be recorded in the bank mysql
the value that is 12:00 records as 15:00 as if the GMT was 00:00 and ours is -03:00. Someone knows what is causing and how I can solve ?
I believe this is the method used to initialize the
DateTimeFormatter
. I would tell you to use the version of the method that uses a Locale when creating FormatterDateTimeFormatter.ofPattern("HH:mm", locale)
and see if it does the way you want it.– mutlei
@mutlei tested and did not work. As I said before going to the bank by debug I saw that is with the right time, is when records even if I see wrong.
– Roknauta
Unbelievable but I changed the mysql . jar to version 5.1.45 and it worked.
– Roknauta
Add as answer to your question, :-)
– Flávio Granato
@Douglas this has kind of mysql server configuration, or the server itself.
– touchmx