[hibernate-issues] [Hibernate-JIRA] Resolved: (HHH-5109) @OneToOne - too many joins

Sharath Reddy (JIRA) noreply at atlassian.com
Sat Jul 3 11:12:13 EDT 2010


     [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-5109?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Sharath Reddy resolved HHH-5109.
--------------------------------

    Resolution: Fixed

> @OneToOne - too many joins
> --------------------------
>
>                 Key: HHH-5109
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5109
>             Project: Hibernate Core
>          Issue Type: Bug
>          Components: annotations, core
>    Affects Versions: 3.5.0-Final
>            Reporter: Marek Romanowski
>            Assignee: Sharath Reddy
>             Fix For: 3.5.x, 3.6
>
>         Attachments: hibernate-one-to-one.zip
>
>
> With classes like this:
> @Entity
> @Proxy(lazy=false)
> class Owner {
>   @javax.persistence.Id
>   @javax.persistence.Column(name = "ID", columnDefinition = "BIGINT")
>   public java.lang.Long getId() {
>     return this.id;
>   }
>   
>   public void setId(java.lang.Long newValue) {
>     this.id = newValue;
>   }
>   
>   private java.lang.Long id;
>   
>   @javax.persistence.OneToOne(targetEntity = Owned.class)
>   @org.hibernate.annotations.Cascade( { org.hibernate.annotations.CascadeType.ALL })
>   @javax.persistence.PrimaryKeyJoinColumn
>   public Owned getOwned() {
>     return this.owned;
>   }
>   
>   public void setOwned(Owned owned) {
>     this.owned = owned;
>     if (owned != null) {
>       owned.setOwner(this);
>     }
>   }
>   
>   private Owned owned;
> }
> @Entity
> @Proxy(lazy=false)
> class Owned {
>   private java.lang.Long id;
>   
>   @javax.persistence.Id
>   @javax.persistence.GeneratedValue(generator = "foreign")
>   @org.hibernate.annotations.GenericGenerator(
>       name = "foreign", 
>       strategy = "foreign", 
>       parameters = { @org.hibernate.annotations.Parameter(name = "property", value = "owner") })
>       @javax.persistence.Column(name = "ID", columnDefinition = "BIGINT")
>       public java.lang.Long getId() {
>     return this.id;
>   }
>   
>   public void setId(java.lang.Long newValue) {
>     this.id = newValue;
>   }
>   
>   @javax.persistence.OneToOne(targetEntity = Owner.class, mappedBy = "owned")
>   @javax.persistence.PrimaryKeyJoinColumn
>   public Owner getOwner() {
>     return this.owner;
>   }
>   
>   public void setOwner(Owner owner) {
>     this.owner = owner;
>   }
>   
>   private Owner owner;
> }
> Idea is to have one to one relation between Owner and Owned mapped by "id" properties in both entities. So for each pair owner.id == owned.id.
> code:
> session.load(Owner.class, 1L)
> turns into SQL:
> select owner0_.ID as ID0_2_, owned1_.ID as ID1_0_, owner2_.ID as ID0_1_
> from Owner owner0_ left outer
>      join Owned owned1_ on owner0_.ID=owned1_.ID 
>      left outer join Owner owner2_ on owned1_.ID=owner2_.ID 
> where owner0_.ID=?
> Isn't it wrong? @OneToOne annotation on getOwner() has mappedBy="owned" property, so I would expect this code to generate SQL with only one join (only "owner join owned"). If this is correct H3 behaviour in this case, then write what should I change in annotations to get described behaviour, please.
> I've attached maven project with one test encapsulating this issue.

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