HHH-8794 cleanup and formatting
This commit is contained in:
parent
a2fcfc602b
commit
e64e89b2cc
|
@ -829,7 +829,6 @@ public abstract class CollectionBinder {
|
|||
String assocClass = oneToMany.getReferencedEntityName();
|
||||
PersistentClass associatedClass = (PersistentClass) persistentClasses.get( assocClass );
|
||||
if ( jpaOrderBy != null ) {
|
||||
final String jpaOrderByFragment = jpaOrderBy.value();
|
||||
final String orderByFragment = buildOrderByClauseFromHql(
|
||||
jpaOrderBy.value(),
|
||||
associatedClass,
|
||||
|
|
|
@ -26,25 +26,23 @@ package org.hibernate.test.annotations.onetomany;
|
|||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Entity
|
||||
@Inheritance(strategy = InheritanceType.JOINED)
|
||||
public class Asset2 implements Serializable {
|
||||
/** */
|
||||
public class Asset implements Serializable {
|
||||
|
||||
@Id
|
||||
@Column(name = "id_asset")
|
||||
private final Integer idAsset;
|
||||
|
||||
@Id
|
||||
@Column(name = "id_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.test = 1;
|
||||
}
|
||||
|
@ -52,7 +50,7 @@ public class Asset2 implements Serializable {
|
|||
/**
|
||||
* @param idAsset
|
||||
*/
|
||||
public Asset2(Integer idAsset) {
|
||||
public Asset(Integer idAsset) {
|
||||
this.idAsset = idAsset;
|
||||
this.test = 1;
|
||||
}
|
||||
|
@ -67,14 +65,14 @@ public class Asset2 implements Serializable {
|
|||
/**
|
||||
* @return the employee
|
||||
*/
|
||||
public Employee2 getEmployee() {
|
||||
public Employee getEmployee() {
|
||||
return employee;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param employee the employee to set
|
||||
*/
|
||||
public void setEmployee(Employee2 employee) {
|
||||
public void setEmployee(Employee employee) {
|
||||
this.employee = employee;
|
||||
}
|
||||
}
|
|
@ -27,28 +27,21 @@ import javax.persistence.Entity;
|
|||
import javax.persistence.PrimaryKeyJoinColumn;
|
||||
import javax.persistence.PrimaryKeyJoinColumns;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Entity
|
||||
@PrimaryKeyJoinColumns({
|
||||
@PrimaryKeyJoinColumn(name = "id_asset"),
|
||||
@PrimaryKeyJoinColumn(name = "id_test")
|
||||
})
|
||||
public class Computer2
|
||||
extends Asset2 {
|
||||
/** */
|
||||
@PrimaryKeyJoinColumns({ @PrimaryKeyJoinColumn(name = "id_asset"), @PrimaryKeyJoinColumn(name = "id_test") })
|
||||
public class Computer extends Asset {
|
||||
|
||||
private String computerName;
|
||||
|
||||
public Computer2() {
|
||||
public Computer() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id
|
||||
*/
|
||||
public Computer2(Integer id) {
|
||||
super(id);
|
||||
public Computer(Integer id) {
|
||||
super( id );
|
||||
}
|
||||
|
||||
/**
|
|
@ -27,28 +27,25 @@ import javax.persistence.*;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Entity
|
||||
public class Employee2 {
|
||||
/** */
|
||||
public class Employee {
|
||||
|
||||
@OneToMany(cascade = CascadeType.ALL, mappedBy = "employee", orphanRemoval = true)
|
||||
@OrderBy
|
||||
private final List<Asset2> assets = new ArrayList<Asset2>();
|
||||
/** */
|
||||
@OrderBy // order by PK
|
||||
private final List<Asset> assets = new ArrayList<Asset>();
|
||||
|
||||
@Id
|
||||
@Column(name = "id")
|
||||
private Integer id;
|
||||
|
||||
public Employee2() {
|
||||
public Employee() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id
|
||||
*/
|
||||
public Employee2(Integer id) {
|
||||
public Employee(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
@ -69,7 +66,7 @@ public class Employee2 {
|
|||
/**
|
||||
* @return the assets
|
||||
*/
|
||||
public List<Asset2> getAssets() {
|
||||
public List<Asset> getAssets() {
|
||||
return assets;
|
||||
}
|
||||
}
|
|
@ -410,36 +410,36 @@ public class OrderByTest extends BaseCoreFunctionalTestCase {
|
|||
assertEquals( "john", forum.getUsers().get( 0 ).getName() );
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-8794")
|
||||
public void testOrderByOnJoinedClassEmpty() {
|
||||
public void testOrderByNoElement() {
|
||||
|
||||
final Session s = openSession();
|
||||
s.getTransaction().begin();
|
||||
|
||||
Employee2 employee = new Employee2(1);
|
||||
Employee employee = new Employee( 1 );
|
||||
|
||||
Computer2 computer = new Computer2(1);
|
||||
computer.setComputerName("Bob's computer");
|
||||
computer.setEmployee(employee);
|
||||
Computer computer = new Computer( 1 );
|
||||
computer.setComputerName( "Bob's computer" );
|
||||
computer.setEmployee( employee );
|
||||
|
||||
Computer2 computer2 = new Computer2(2);
|
||||
computer2.setComputerName("Alice's computer");
|
||||
computer2.setEmployee(employee);
|
||||
Computer computer2 = new Computer( 2 );
|
||||
computer2.setComputerName( "Alice's computer" );
|
||||
computer2.setEmployee( employee );
|
||||
|
||||
s.save(employee);
|
||||
s.save(computer2);
|
||||
s.save(computer);
|
||||
s.save( employee );
|
||||
s.save( computer2 );
|
||||
s.save( computer );
|
||||
|
||||
s.flush();
|
||||
s.clear();
|
||||
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(1, employee.getAssets().get(0).getIdAsset().intValue());
|
||||
assertEquals(2, employee.getAssets().get(1).getIdAsset().intValue());
|
||||
assertEquals( 2, employee.getAssets().size() );
|
||||
assertEquals( 1, employee.getAssets().get( 0 ).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,
|
||||
BankAccount.class, Transaction.class,
|
||||
Comment.class, Forum.class, Post.class, User.class,
|
||||
Asset2.class, Computer2.class, Employee2.class
|
||||
Asset.class, Computer.class, Employee.class
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue