HHH-7767 JoinWalker creates ".." substring in association path

This commit is contained in:
Alex Kalashnikov 2012-11-08 21:27:42 +04:00
parent 785e2d869e
commit 9f462834da
5 changed files with 191 additions and 1 deletions

View File

@ -561,7 +561,7 @@ public class JoinWalker {
0,
persister,
alias,
path.append( "" ),
path,
currentDepth
);
}

View File

@ -0,0 +1,53 @@
package org.hibernate.test.annotations.idmanytoone;
import java.io.Serializable;
import java.util.Set;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
/**
* @author Alex Kalashnikov
*/
@Entity
@Table(name = "idmanytoone_course")
public class Course implements Serializable {
@Id
@GeneratedValue
private int id;
private String name;
@OneToMany(mappedBy = "course")
private Set<CourseStudent> students;
public Course() {
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Set<CourseStudent> getStudents() {
return students;
}
public void setStudents(Set<CourseStudent> students) {
this.students = students;
}
}

View File

@ -0,0 +1,57 @@
package org.hibernate.test.annotations.idmanytoone;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
/**
* @author Alex Kalashnikov
*/
@Entity
@Table(name = "idmanytoone_course_student")
public class CourseStudent implements Serializable {
@Id
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "course_id")
private Course course;
@Id
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "student_id")
private Student student;
private String value;
public CourseStudent() {
}
public Course getCourse() {
return course;
}
public void setCourse(Course course) {
this.course = course;
}
public Student getStudent() {
return student;
}
public void setStudent(Student student) {
this.student = student;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}

View File

@ -23,6 +23,8 @@
*/
package org.hibernate.test.annotations.idmanytoone;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.junit.Test;
import org.hibernate.Session;
@ -64,6 +66,28 @@ public class IdManyToOneTest extends BaseCoreFunctionalTestCase {
s.close();
}
@Test
public void testCriteriaRestrictionOnIdManyToOne() {
Session s = openSession();
s.beginTransaction();
s.createQuery( "from Course c join c.students cs join cs.student s where s.name = 'Foo'" ).list();
Criteria criteria = s.createCriteria( Course.class );
criteria.createCriteria( "students" ).createCriteria( "student" ).add( Restrictions.eq( "name", "Foo" ) );
criteria.list();
Criteria criteria2 = s.createCriteria( Course.class );
criteria2.createAlias( "students", "cs" );
criteria2.add( Restrictions.eq( "cs.value", "Bar" ) );
criteria2.createAlias( "cs.student", "s" );
criteria2.add( Restrictions.eq( "s.name", "Foo" ) );
criteria2.list();
s.getTransaction().commit();
s.close();
}
@Override
protected Class[] getAnnotatedClasses() {
return new Class[] {
@ -74,6 +98,9 @@ public class IdManyToOneTest extends BaseCoreFunctionalTestCase {
CardField.class,
Card.class,
Project.class,
Course.class,
Student.class,
CourseStudent.class,
//tested only through deployment
//ANN-590 testIdClassManyToOneWithReferenceColumn

View File

@ -0,0 +1,53 @@
package org.hibernate.test.annotations.idmanytoone;
import java.io.Serializable;
import java.util.Set;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
/**
* @author Alex Kalashnikov
*/
@Entity
@Table(name = "idmanytoone_student")
public class Student implements Serializable {
@Id
@GeneratedValue
private int id;
private String name;
@OneToMany(mappedBy = "student")
private Set<CourseStudent> courses;
public Student() {
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Set<CourseStudent> getCourses() {
return courses;
}
public void setCourses(Set<CourseStudent> courses) {
this.courses = courses;
}
}