Skip to content

Commit

Permalink
HHH-6813 Corrected EntityType#getRHSUniqueKeyPropertyName() and added
Browse files Browse the repository at this point in the history
regression test.
  • Loading branch information
brmeyer committed Jul 8, 2013
1 parent bc576e7 commit febde59
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 2 deletions.
Expand Up @@ -201,7 +201,9 @@ public boolean isReferenceToPrimaryKey() {
}

public String getRHSUniqueKeyPropertyName() {
return uniqueKeyPropertyName;
// Return null if this type references a PK. This is important for
// associations' use of mappedBy referring to a derived ID.
return referenceToPrimaryKey ? null : uniqueKeyPropertyName;
}

public String getLHSPropertyName() {
Expand Down
Expand Up @@ -26,6 +26,9 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
Expand Down Expand Up @@ -80,11 +83,50 @@ public void testSelectWithDerivedId() {
s.close();
}

@Test
@TestForIssue(jiraKey = "HHH-6813")
// Regression test utilizing multiple types of queries.
public void testCase() {
Session s = openSession();
s.getTransaction().begin();

Person p = new Person();
p.setName( "Alfio" );
PersonInfo pi = new PersonInfo();
pi.setId( p );
pi.setInfo( "Some information" );
s.persist( p );
s.persist( pi );

s.getTransaction().commit();
s.clear();

s.getTransaction().begin();

Query q = s.getNamedQuery( "PersonQuery" );
List<Person> persons = q.list();
assertEquals( persons.size(), 1 );
assertEquals( persons.get( 0 ).getName(), "Alfio" );

s.getTransaction().commit();
s.clear();

s.getTransaction().begin();

p = (Person) s.get( Person.class, persons.get( 0 ).getId() );
assertEquals( p.getName(), "Alfio" );

s.getTransaction().commit();
s.close();
}

@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] {
Foo.class,
Bar.class
Bar.class,
Person.class,
PersonInfo.class
};
}

Expand Down
@@ -0,0 +1,77 @@
package org.hibernate.test.annotations.derivedidentities.bidirectional;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;

@Entity
@NamedQuery(name="PersonQuery", query="SELECT p FROM Person p")
public class Person
implements Serializable
{
private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Integer id;

@Basic
private String name;

@OneToOne(mappedBy="id")
private PersonInfo personInfo;

public Integer getId()
{
return this.id;
}

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

public String getName() {
return this.name;
}

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

public int hashCode()
{
int hash = 0;
hash += (this.id != null ? this.id.hashCode() : 0);
return hash;
}

public boolean equals(Object object)
{
if (!(object instanceof Person)) {
return false;
}
Person other = (Person)object;

return ((this.id != null) || (other.id == null)) && ((this.id == null) || (this.id.equals(other.id)));
}

public String toString()
{
return "nogroup.hibertest.Person[ id=" + this.id + " ]";
}

public PersonInfo getPersonInfo()
{
return this.personInfo;
}

public void setPersonInfo(PersonInfo personInfo)
{
this.personInfo = personInfo;
}
}
@@ -0,0 +1,60 @@
package org.hibernate.test.annotations.derivedidentities.bidirectional;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToOne;

@Entity
public class PersonInfo
implements Serializable
{
private static final long serialVersionUID = 1L;

@Id
@OneToOne
private Person id;

@Basic
private String info;

public Person getId()
{
return this.id;
}

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

public String getInfo() {
return this.info;
}

public void setInfo(String info) {
this.info = info;
}

public int hashCode()
{
int hash = 0;
hash += (this.id != null ? this.id.hashCode() : 0);
return hash;
}

public boolean equals(Object object)
{
if (!(object instanceof PersonInfo)) {
return false;
}
PersonInfo other = (PersonInfo)object;

return ((this.id != null) || (other.id == null)) && ((this.id == null) || (this.id.equals(other.id)));
}

public String toString()
{
return "nogroup.hibertest.PersonInfo[ id=" + this.id + " ]";
}
}

0 comments on commit febde59

Please sign in to comment.