Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java in General
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Java in General
Strange data retrieved in many to one mapping
Gil Carvalho
Ranch Hand
Posts: 80
posted 10 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hello
I'm having a strange data received inmy
jsp
concerning many to one mapping
I receive like this from my mapped entity
gmc.gestaxi.domain.Veiculo@7843566e
This is my main class
@Entity @Table(name = "VEICULO", schema = "GESTAOTAXI") public class Veiculo implements Serializable { private static final long serialVersionUID = 1L; private int codVeiculo; private String marca; private String modelo; private String matricula; private String seguro; private String inspecao; private Set<EmpregadoVeiculo> empregadoVeiculos = new HashSet<>(0); public Veiculo() { } @Id @Column(name = "COD_VEICULO", nullable = false) @Basic(fetch = FetchType.EAGER) @GeneratedValue(strategy = GenerationType.AUTO) public int getCodVeiculo() { return this.codVeiculo; } public void setCodVeiculo(int codVeiculo) { this.codVeiculo = codVeiculo; } @Column(name = "MARCA", length = 100) public String getMarca() { return this.marca; } public void setMarca(String marca) { this.marca = marca; } @Column(name = "MODELO", length = 100) public String getModelo() { return this.modelo; } public void setModelo(String modelo) { this.modelo = modelo; } @Column(name = "MATRICULA", length = 20) public String getMatricula() { return this.matricula; } public void setMatricula(String matricula) { this.matricula = matricula; } @Column(name = "SEGURO", length = 100) public String getSeguro() { return this.seguro; } public void setSeguro(String seguro) { this.seguro = seguro; } @Column(name = "INSPECAO", length = 100) public String getInspecao() { return this.inspecao; } public void setInspecao(String inspecao) { this.inspecao = inspecao; } @OneToMany(cascade = CascadeType.REMOVE, fetch = FetchType.EAGER, mappedBy = "veiculo") public Set<EmpregadoVeiculo> getEmpregadoVeiculos() { return this.empregadoVeiculos; } public void setEmpregadoVeiculos(Set<EmpregadoVeiculo> empregadoVeiculos) { this.empregadoVeiculos = empregadoVeiculos; } }
And the related class
@Entity @Table(name = "EMPREGADO_VEICULO", schema = "GESTAOTAXI") public class EmpregadoVeiculo implements Serializable { private static final long serialVersionUID = 1L; private int codEmpregadoVeiculo; private Veiculo veiculo; private Empregado empregado; private Timestamp horaData; private Set<Servico> servicos = new HashSet<>(0); private Set<Reserva> reservas = new HashSet<>(0); public EmpregadoVeiculo() { } public EmpregadoVeiculo(int codEmpregadoVeiculo) { this.codEmpregadoVeiculo = codEmpregadoVeiculo; } @Id @Column(name = "COD_EMPREGADO_VEICULO", nullable = false) @GeneratedValue(strategy = GenerationType.AUTO) public int getCodEmpregadoVeiculo() { return this.codEmpregadoVeiculo; } public void setCodEmpregadoVeiculo(int codEmpregadoVeiculo) { this.codEmpregadoVeiculo = codEmpregadoVeiculo; } @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name = "COD_VEICULO") public Veiculo getVeiculo() { return this.veiculo; } public void setVeiculo(Veiculo veiculo) { this.veiculo = veiculo; } @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name = "COD_EMPREGADO") public Empregado getEmpregado() { return this.empregado; } public void setEmpregado(Empregado empregado) { this.empregado = empregado; } @Column(name = "HORA_DATA") public Timestamp getHoraData() { return this.horaData; } public void setHoraData(Timestamp horaData) { this.horaData = horaData; } @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "empregadoVeiculo") public Set<Servico> getServicos() { return this.servicos; } public void setServicos(Set<Servico> servicos) { this.servicos = servicos; } @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "empregadoVeiculo") public Set<Reserva> getReservas() { return this.reservas; } public void setReservas(Set<Reserva> reservas) { this.reservas = reservas; } }
Any help please??
Thanks
Paul Clapham
Marshal
Posts: 28193
95
I like...
posted 10 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
It's a Veiculo object. Why do you find that strange? Isn't that what you would expect?
Gil Carvalho
Ranch Hand
Posts: 80
posted 10 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi
Thank for posting
No, i expect a value like
A
B
C
values that i have in my database...
not this
gmc.gestaxi.domain.Veiculo@7843566e
This is unreadable, how can i achieve that??
Thank you
Paul Clapham
Marshal
Posts: 28193
95
I like...
posted 10 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
That's what the toString() method of Veiculo returns. Since you didn't override it, you get what the toString() method of Object returns. If you want something else, then write a toString() method which returns a suitable
String
object.
Gil Carvalho
Ranch Hand
Posts: 80
posted 10 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Thank Paul
I'm lost, i understand that i have to use @Override in toString but wich field? The one i want to be listed?
private int codVeiculo; private String marca; private String modelo; private String matricula; private String seguro; private String inspecao; private Set<EmpregadoVeiculo> empregadoVeiculos = new HashSet<>(0);
Or just the one of the relationship, in this case is "empregadoVeiculos " to @Override?
Thanks and sorry for my silly questions but i'm new in hibernate
Regards
Paul Clapham
Marshal
Posts: 28193
95
I like...
posted 10 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
If you don't like what the default toString() method returns for a Veiculo object, it's up to you to decide what you want instead.
Here's what the code would look like, as part of the Veiculo class:
@Override public String toString() { // return some String value which represents the Veiculo object to a human observer }
Jayesh A Lalwani
Rancher
Posts: 2759
32
I like...
posted 10 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Moved
thread
to
java
forum because it's not a spring question.
Gil Carvalho
Ranch Hand
Posts: 80
posted 10 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Thank you Paul
It was what i was looking for.
Best regards
Don't get me started about those stupid
light bulbs
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
deleting causes : not-null property references a null or transient value
Datetimepicker return null
hibernat creating the tables without cascade
Bean property 'xxxxx' is not readable or has an invalid getter
HIbernate Mapping problem
More...