-->
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.  [ 1 post ] 
Author Message
 Post subject: sql generated cause:Column 'id' in where clause is ambiguous
PostPosted: Tue Dec 28, 2010 2:14 pm 
Newbie

Joined: Tue Dec 28, 2010 1:48 pm
Posts: 3
Hi,

I'm using jpa and hibernate.
I have the following error message :

Column 'id' in where clause is ambiguous

It's caused by a bad sql generated.

I've got two tables like this :
Table Entity (id, field1, field2)
Table Chapter (id, name)

My mapping :

@MappedSuperclass
public class TemporalBehavior implements Serializable{

// mapping field1
// mapping field2 ...
//
}


@Entity
@Table(name = "entity")
@Inheritance(strategy=InheritanceType.JOINED)
public abstract class EntityAff extends TemporalBehavior implements Nameable, Serializable {

/**
*
*/
private static final long serialVersionUID = 6883572560586578684L;

protected final Log logger = LogFactory.getLog(getClass());

protected Integer id;


public EntityAffiliation() {
}


@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id", unique = true, nullable = false)
public Integer getId() {
return this.id;
}

public void setId(Integer id) {
this.id = id;
}

}

@Entity
@Indexed
@Table(name="chapter")
@PrimaryKeyJoinColumn(name="id")
public class Chapter extends EntityAff {

/**
*
*/
private static final long serialVersionUID = -6912952785079360312L;

@Field(index=Index.TOKENIZED, store=Store.NO)
@NotNull
@Size(min=1 , max=100)
protected String name;


public Chapter() {
}

public Chapter(String name) {
...
}

@Column(name="name", nullable=false, length=100)
public String getName() {
return this.name;
}

public void setName(String name) {
this.name = name;
}
}


When I'm executing the following query :

String query = "DELETE Chapter o WHERE o.id IN (:ids)";
return em.createQuery(query).setParameter("ids",ids).executeUpdate();

I obtain sql generated :
Hibernate:
insert
into
HT_chapter
select
chapter0_.id as id_
from
chapter chapter0_
inner join
entity chapter0_1_
on chapter0_.id=chapter0_1_.id
where
id in (
? , ?
)

And obviously this error message : "Column 'id' in where clause is ambiguous"
Because 'id' in the where clause can reference table entity or table chapter

The good generated sql should be :
...
where
chapter0_.id in (
? , ?
)
Do you see an error in my mapping ? Or do see any solution to this problem ?

Thanks much

Nicolas


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

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.