HHH-8794 cleanup and formatting

This commit is contained in:
Brett Meyer 2013-12-12 16:21:31 -05:00
parent a2fcfc602b
commit e64e89b2cc
5 changed files with 42 additions and 55 deletions

View File

@ -829,7 +829,6 @@ public abstract class CollectionBinder {
String assocClass = oneToMany.getReferencedEntityName(); String assocClass = oneToMany.getReferencedEntityName();
PersistentClass associatedClass = (PersistentClass) persistentClasses.get( assocClass ); PersistentClass associatedClass = (PersistentClass) persistentClasses.get( assocClass );
if ( jpaOrderBy != null ) { if ( jpaOrderBy != null ) {
final String jpaOrderByFragment = jpaOrderBy.value();
final String orderByFragment = buildOrderByClauseFromHql( final String orderByFragment = buildOrderByClauseFromHql(
jpaOrderBy.value(), jpaOrderBy.value(),
associatedClass, associatedClass,

View File

@ -26,25 +26,23 @@ package org.hibernate.test.annotations.onetomany;
import javax.persistence.*; import javax.persistence.*;
import java.io.Serializable; import java.io.Serializable;
/**
*
*/
@Entity @Entity
@Inheritance(strategy = InheritanceType.JOINED) @Inheritance(strategy = InheritanceType.JOINED)
public class Asset2 implements Serializable { public class Asset implements Serializable {
/** */
@Id @Id
@Column(name = "id_asset") @Column(name = "id_asset")
private final Integer idAsset; private final Integer idAsset;
@Id @Id
@Column(name = "id_test") @Column(name = "id_test")
private final Integer test; private final Integer test;
/** */
@ManyToOne(cascade = {CascadeType.ALL})
@JoinColumn(nullable = false)
private Employee2 employee;
public Asset2() { @ManyToOne(cascade = { CascadeType.ALL })
@JoinColumn(nullable = false)
private Employee employee;
public Asset() {
this.idAsset = 0; this.idAsset = 0;
this.test = 1; this.test = 1;
} }
@ -52,7 +50,7 @@ public class Asset2 implements Serializable {
/** /**
* @param idAsset * @param idAsset
*/ */
public Asset2(Integer idAsset) { public Asset(Integer idAsset) {
this.idAsset = idAsset; this.idAsset = idAsset;
this.test = 1; this.test = 1;
} }
@ -67,14 +65,14 @@ public class Asset2 implements Serializable {
/** /**
* @return the employee * @return the employee
*/ */
public Employee2 getEmployee() { public Employee getEmployee() {
return employee; return employee;
} }
/** /**
* @param employee the employee to set * @param employee the employee to set
*/ */
public void setEmployee(Employee2 employee) { public void setEmployee(Employee employee) {
this.employee = employee; this.employee = employee;
} }
} }

View File

@ -27,28 +27,21 @@ import javax.persistence.Entity;
import javax.persistence.PrimaryKeyJoinColumn; import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.PrimaryKeyJoinColumns; import javax.persistence.PrimaryKeyJoinColumns;
/**
*
*/
@Entity @Entity
@PrimaryKeyJoinColumns({ @PrimaryKeyJoinColumns({ @PrimaryKeyJoinColumn(name = "id_asset"), @PrimaryKeyJoinColumn(name = "id_test") })
@PrimaryKeyJoinColumn(name = "id_asset"), public class Computer extends Asset {
@PrimaryKeyJoinColumn(name = "id_test")
})
public class Computer2
extends Asset2 {
/** */
private String computerName; private String computerName;
public Computer2() { public Computer() {
} }
/** /**
* @param id * @param id
*/ */
public Computer2(Integer id) { public Computer(Integer id) {
super(id); super( id );
} }
/** /**

View File

@ -27,28 +27,25 @@ import javax.persistence.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
/**
*
*/
@Entity @Entity
public class Employee2 { public class Employee {
/** */
@OneToMany(cascade = CascadeType.ALL, mappedBy = "employee", orphanRemoval = true) @OneToMany(cascade = CascadeType.ALL, mappedBy = "employee", orphanRemoval = true)
@OrderBy @OrderBy // order by PK
private final List<Asset2> assets = new ArrayList<Asset2>(); private final List<Asset> assets = new ArrayList<Asset>();
/** */
@Id @Id
@Column(name = "id") @Column(name = "id")
private Integer id; private Integer id;
public Employee2() { public Employee() {
} }
/** /**
* @param id * @param id
*/ */
public Employee2(Integer id) { public Employee(Integer id) {
this.id = id; this.id = id;
} }
@ -69,7 +66,7 @@ public class Employee2 {
/** /**
* @return the assets * @return the assets
*/ */
public List<Asset2> getAssets() { public List<Asset> getAssets() {
return assets; return assets;
} }
} }

View File

@ -410,36 +410,36 @@ public class OrderByTest extends BaseCoreFunctionalTestCase {
assertEquals( "john", forum.getUsers().get( 0 ).getName() ); assertEquals( "john", forum.getUsers().get( 0 ).getName() );
} }
@Test @Test
@TestForIssue(jiraKey = "HHH-8794") @TestForIssue(jiraKey = "HHH-8794")
public void testOrderByOnJoinedClassEmpty() { public void testOrderByNoElement() {
final Session s = openSession(); final Session s = openSession();
s.getTransaction().begin(); s.getTransaction().begin();
Employee2 employee = new Employee2(1); Employee employee = new Employee( 1 );
Computer2 computer = new Computer2(1); Computer computer = new Computer( 1 );
computer.setComputerName("Bob's computer"); computer.setComputerName( "Bob's computer" );
computer.setEmployee(employee); computer.setEmployee( employee );
Computer2 computer2 = new Computer2(2); Computer computer2 = new Computer( 2 );
computer2.setComputerName("Alice's computer"); computer2.setComputerName( "Alice's computer" );
computer2.setEmployee(employee); computer2.setEmployee( employee );
s.save(employee); s.save( employee );
s.save(computer2); s.save( computer2 );
s.save(computer); s.save( computer );
s.flush(); s.flush();
s.clear(); s.clear();
sessionFactory().getCache().evictEntityRegions(); sessionFactory().getCache().evictEntityRegions();
employee = (Employee2) s.get(Employee2.class, employee.getId()); employee = (Employee) s.get( Employee.class, employee.getId() );
assertEquals(2, employee.getAssets().size()); assertEquals( 2, employee.getAssets().size() );
assertEquals(1, employee.getAssets().get(0).getIdAsset().intValue()); assertEquals( 1, employee.getAssets().get( 0 ).getIdAsset().intValue() );
assertEquals(2, employee.getAssets().get(1).getIdAsset().intValue()); assertEquals( 2, employee.getAssets().get( 1 ).getIdAsset().intValue() );
} }
@ -450,7 +450,7 @@ public class OrderByTest extends BaseCoreFunctionalTestCase {
Monkey.class, Visitor.class, Box.class, Item.class, Monkey.class, Visitor.class, Box.class, Item.class,
BankAccount.class, Transaction.class, BankAccount.class, Transaction.class,
Comment.class, Forum.class, Post.class, User.class, Comment.class, Forum.class, Post.class, User.class,
Asset2.class, Computer2.class, Employee2.class Asset.class, Computer.class, Employee.class
}; };
} }
} }