-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Error ORA-00918: column ambiguously defined using ManyToOne
PostPosted: Wed Apr 09, 2014 9:41 am 
Beginner
Beginner

Joined: Sat Jun 24, 2006 7:05 am
Posts: 20
I try to read the following entity but the sql produced generates the following error : ORA-00918: column ambiguously defined.
What's wrong ?
The problem seems to come out because the field cges41 is read twice, however I need both the field and the related manytoone object.
Any suggestion ?
Tks
Tullio

Code:
@Entity
@Table(name="V41TIPI_EVENTO")
public class V41tipiEvento extends EntityBase<S41tipiEventoPk> {

   private static final long serialVersionUID = 1L;
   
    @Column(name="DESS41")
   private String dess41;
    @Column(name="CGES41")
   private String cges41;
    @ManyToOne
    @Fetch(value = FetchMode.JOIN)
    @JoinColumn(name="cges41", referencedColumnName="cods42")
    private S42gruppiEvento gruppiEvento;


Top
 Profile  
 
 Post subject: Re: Error ORA-00918: column ambiguously defined using ManyToOne
PostPosted: Wed Apr 09, 2014 2:16 pm 
Newbie

Joined: Mon Apr 07, 2014 10:20 am
Posts: 12
What happens if you change your @JoinColumn annotation to:
@JoinColumn(name="cges41", referencedColumnName="cods42", insertable = false, updatable = false)

OR, in this sort of scenario, I might consider something like this instead:
Code:
// Remove this
// @Column(name="CGES41")
// private String cges41;

// And just have a getter which accesses your mapped object:
public String getCges41() {
    return (gruppiEvento != null) ? gruppiEvento.getCods42() : null;
}


Top
 Profile  
 
 Post subject: Re: Error ORA-00918: column ambiguously defined using ManyToOne
PostPosted: Thu Apr 10, 2014 3:33 am 
Beginner
Beginner

Joined: Sat Jun 24, 2006 7:05 am
Posts: 20
Insertable and updatable are not relevant because the problem comes out in select and not in update or insert.
The solution You proposed could work however I still don't understand why it happens.
Is it a bug ?
Tks.


Top
 Profile  
 
 Post subject: Re: Error ORA-00918: column ambiguously defined using ManyToOne
PostPosted: Thu Apr 10, 2014 10:25 am 
Newbie

Joined: Mon Apr 07, 2014 10:20 am
Posts: 12
What I have found is you have to add these attributes when you have the same column mapped multiple times on an entity.

I think this is because Hibernate wants only one of these fields to actually "own" the column/mapping value. By setting the insertable=false, updateable=false attributes you're telling Hibernate to NOT change this particular column for this particular mapping.

In other words, when you have something like this:

Code:
@Column(name="CGES41")
private String cges41;

@ManyToOne
@JoinColumn(name="cges41", referencedColumnName="cods42")
private S42gruppiEvento gruppiEvento;


...then what happens if you change the 'gruppiEvento' object but don't change the value in the cges41 field? When it comes time to flush data to the database, how does Hibernate know which value to persist?

By setting the "insertable = false, updatable = false" attributes on the @JoinColumn mapping, then you're telling Hibernate that the field cges41 is what actually owns the column value. The 'gruppiEvento' object will be populated, but it doesn't control the cges41 column on this table. If you change the 'gruppiEvento' object you also need to ensure you update the cges41 field.

Of course, typically I would expect to see the exception "org.hibernate.MappingException: Repeated column in mapping..." in this sort of situation... So maybe there's something else in your entities that you aren't showing causing your exception.


Top
 Profile  
 
 Post subject: Re: Error ORA-00918: column ambiguously defined using ManyToOne
PostPosted: Fri Apr 11, 2014 6:57 am 
Beginner
Beginner

Joined: Sat Jun 24, 2006 7:05 am
Posts: 20
Done but the problem is still there.
Tks


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.