This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

org.hibernate.MappingException: Repeated column in mapping

 
Manuel Jordan
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Members

I am working with the follow dependencies


Among many entities I have these two Asignado and TraspasoAsignado

The first defined in this way




The Second


I get this error




OK, is clear that idAsignado is repetead

I already did a research on the forum and the most common solution is do

@JoinColumn(name="idAsignado", insertable=false, updatable=false) but I did realize the follow

Even if I use insertable=false and updatable=false I will have one column that you could not write to or update to; if that so, then, when hibernate it's retrieving the data how it will know which property to fill, with only one column for 2 properties.

I want get the follow row representation

Asignado
PK
Asg1 ...
Asg2 ...
Asg3 ...

TraspasoAsignado
PK
Tr1 .. Asg1 Asg2 ...
Tr2 .. Asg10 Asg22 ...
Tr3 .. Asg15 Asg50 ...

Obviously each FK value for idAsignado in TraspasoAsignado entity never must be the same

How I could resolve this?

Thanks in advanced
 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Obviously each FK value for idAsignado in TraspasoAsignado entity never must be the same

I don't understand. How can there be two different values occupying the same cell in the database? Why can't there be two columns in the traspasoasignado table (asignadoOrigen and asignadoDestino )

 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
reading it again, I see that there are two columns and you want asignadoOrigen and asignadoDestino to both map to idAsignado in the Asignado table. This is still a problem because you have defined A OneToOne relationship between Asignado and TraspasoAsignado entities. idAsignado cannot be two different values at once.
 
Manuel Jordan
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Tim


reading it again, I see that there are two columns and you want asignadoOrigen and asignadoDestino to both map to idAsignado in the Asignado table. This is still a problem because you have defined A OneToOne relationship between Asignado and TraspasoAsignado entities. idAsignado cannot be two different values at once.


I already solved this, refactoring the table in two, a header(father) and a detail(child), each child (two in this case) with the FK instance (relation 1..1) and the father controlling each child relation

Thanks anyway !
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic