[hibernate-issues] [Hibernate-JIRA] Created: (HHH-4795) Comparing OneToOne mappedBy column to null generates wrong SQL

Uros Majeric (JIRA) noreply at atlassian.com
Thu Jan 14 04:52:31 EST 2010


Comparing OneToOne mappedBy column to null generates wrong SQL
--------------------------------------------------------------

                 Key: HHH-4795
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4795
             Project: Hibernate Core
          Issue Type: Bug
         Environment: Hibernate core 3.3.2.GA
Postgresql 8.4
            Reporter: Uros Majeric


I have two entities:
@Entity
@Table(name = "beer_keg")
public class Keg implements Serializable {
	@Id
	@GeneratedValue
	@Column(name = "bkid")
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}
	
	@OneToOne(mappedBy="keg", fetch=FetchType.LAZY, optional=true)
	public KegValveCombination getCombination() {
		return combination;
	}
	
	void setCombination(KegValveCombination combination) {
		this.combination = combination;
	}
}

and 

@Entity
@Table(name="keg_valve_combination")
public class KegValveCombination implements Serializable {
	@Id
	@GeneratedValue
	@Column(name="id", nullable=false)
	public Long getId() {
		return id;
	}

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

	@OneToOne(cascade=CascadeType.ALL)
	@JoinColumn(name="keg", nullable=false, unique=true)
	public Keg getKeg() {
		return keg;
	}

	public void setKeg(Keg keg) {
		this.keg = keg;
	}
}

if I create query:
 em.createQuery("FROM Keg k WHERE k.combination is null").getResultList();

hibernate generates sql like:
 select keg0_.* from beer_keg keg0_ where keg0_.bkid is null

but it should be:
 select keg0_.* from beer_keg keg0_ left join keg_valve_combination kegvalveco1_ on keg0_.bkid=kegvalveco1_.keg where (kegvalveco1_.keg is null)

thanks, Uros

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list