[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-5109?page=c...
]
Sharath Reddy commented on HHH-5109:
------------------------------------
Hi Marek,
Can you make the following changes:
On the 'Owned' class, remove the @PrimaryKeyJoinColumn annotation (It can only be
on one side). Also, set optional=false on the @OneToOne relationship on this side. This
should eliminate the extra join.
Can you let me know if this fixes your issue?
@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",
optional=false)
public Owner getOwner() { return this.owner; }
@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
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....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira