I have these 3 classes as a template.
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 Destination:
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 hour attribute which is a LocalTime
, I fill in 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 have the time 12:00 .
My persistence class:
public class ServiceBase {
@PersistenceContext(unitName = "tracker")
protected EntityManager em;
public void insert(Objeto objeto) {
this.em.persist(objeto);
}
}
Until then, it's OK, when it's written to the bank mysql
the value that is 12:00 writes as 15:00 as if GMT was 00:00 and ours is -03: 00. Does anyone know what's causing it and how can I resolve it?