[hibernate-issues] [Hibernate-JIRA] Created: (EJB-462) 3.5.beta1: Wrong query generation for @EmbeddedId and @MappedById

Juergen Zimmermann (JIRA) noreply at atlassian.com
Sat Aug 22 04:41:15 EDT 2009


3.5.beta1: Wrong query generation for @EmbeddedId and @MappedById
-----------------------------------------------------------------

                 Key: EJB-462
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/EJB-462
             Project: Hibernate Entity Manager
          Issue Type: Bug
    Affects Versions: 3.5
         Environment: Hibernate 3.5.beta1
            Reporter: Juergen Zimmermann


I'm having this entity class:
@Entity
@Table(name="reklamation")
@NamedQueries({
@NamedQuery(name  = "findReklamationenByKundeId",
query = "SELECT r  FROM Reklamation r  WHERE r.bestellung.kunde.id = :kundeId ORDER BY r.bestellung.id")
})
public class Reklamation implements Serializable {
	@EmbeddedId
	@AttributeOverride(name="bestellungId", column=@Column(name="bestellung_fk"))
	private ReklamationId id = new ReklamationId();
	
	@MappedById("bestellungId")
	@ManyToOne
	private Bestellung bestellung;
	...
	@Embeddable
	public static class ReklamationId implements Serializable {
		public Long bestellungId;
		public Date datum;
	}
}

The owner class:
@Entity
@Table(name="bestellung")
@NamedQueries({...})
public class Bestellung implements java.io.Serializable {
	@Id
	@GeneratedValue(strategy=AUTO, generator="bestellung_sequence_name")
	@SequenceGenerator(name="bestellung_sequence_name", sequenceName="bestellung_b_id_seq", allocationSize=1)
	@Column(name="b_id", unique=true, nullable=false, precision=20)
	private Long id = null;
	...
}

The table definitions in PostgreSQL:
CREATE TABLE reklamation(
	bestellung_fk BIGINT NOT NULL,
	datum DATE NOT NULL,
	...
	PRIMARY KEY(bestellung_fk, datum),
	FOREIGN KEY (bestellung_fk) REFERENCES bestellung(b_id)
);
CREATE TABLE bestellung(
	b_id BIGSERIAL NOT NULL PRIMARY KEY,
	kunde_fk BIGINT NOT NULL,
	...
	FOREIGN KEY (kunde_fk) REFERENCES kunde(k_id)
);

The wrong generation of SQL regarding @EmbeddedId and @MappedById:
2009-08-22 09:04:06,469 DEBUG org.hibernate.SQL - 
    /* named HQL query findReklamationenByKundeId */ select
        reklamatio0_.bestellung_fk as bestellung1_34_,
        reklamatio0_.datum as datum34_,
        reklamatio0_.bestellung_b_id as bestellung4_34_,
        reklamatio0_.inhalt as inhalt34_ 
    from
        reklamation reklamatio0_,
        bestellung bestellung1_ 
    where
        reklamatio0_.bestellung_b_id=bestellung1_.b_id 
        and bestellung1_.kunde_fk=? 
    order by
        reklamatio0_.bestellung_b_id

-- 
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