Merge branch 'master' into HHH-5981

This commit is contained in:
Steve Ebersole 2011-03-04 12:46:15 -06:00
commit 0093974180
6 changed files with 73 additions and 2 deletions

View File

@ -53,7 +53,7 @@ public class AuthenticationHandler extends DefaultTask {
@TaskAction
public void configureUploadAuthentication() {
// todo : unfortunately I have no idea how to apply this to non MavenDeployer-type repos...
uploadTask.getRepositories().withType( MavenDeployer.class ).allObjects(
uploadTask.getRepositories().withType( MavenDeployer.class ).all(
new Action<MavenDeployer>() {
public void execute(MavenDeployer deployer) {
final RemoteRepository repository = deployer.getRepository();

View File

@ -43,7 +43,7 @@ public class UploadAuthenticationManager implements Plugin<Project> {
// code for just that.
final AuthenticationProviderRegistry registry = new AuthenticationProviderRegistry();
project.getTasks().withType( Upload.class ).allTasks(
project.getTasks().withType( Upload.class ).all(
new Action<Upload>() {
@Override
public void execute(final Upload uploadTask) {

View File

@ -269,6 +269,26 @@ public class ManyToOneTest extends TestCase {
s.close();
}
public void testManyToOneNonPkSecondaryTable() throws Exception {
Session s = openSession();
Transaction tx = s.beginTransaction();
Order order = new Order();
order.setOrderNbr( "123" );
s.persist( order );
OrderLine ol = new OrderLine();
ol.setItem( "Mouse" );
ol.setReplacementOrder( order );
s.persist( ol );
s.flush();
s.clear();
ol = (OrderLine) s.get( OrderLine.class, ol.getId() );
assertNotNull( ol.getReplacementOrder() );
assertEquals( "123", ol.getReplacementOrder().getOrderNbr() );
assertFalse( ol.getReplacementOrder().getOrderLines().contains( ol ) );
tx.rollback();
s.close();
}
public void testTwoManyToOneNonPk() throws Exception {
//2 many to one non pk pointing to the same referencedColumnName should not fail
Session s = openSession();

View File

@ -6,15 +6,18 @@ import javax.persistence.Id;
import javax.persistence.GeneratedValue;
import javax.persistence.ManyToOne;
import javax.persistence.JoinColumn;
import javax.persistence.SecondaryTable;
/**
* @author Emmanuel Bernard
*/
@Entity
@SecondaryTable(name="OrderLine_Extension")
public class OrderLine {
private Integer id;
private String item;
private Order order;
private Order replacementOrder;
@Id @GeneratedValue
public Integer getId() {
@ -42,4 +45,14 @@ public class OrderLine {
public void setOrder(Order order) {
this.order = order;
}
@ManyToOne
@JoinColumn(name="replacement_order_nbr", table="OrderLine_Extension", referencedColumnName = "order_nbr")
public Order getReplacementOrder() {
return replacementOrder;
}
public void setReplacementOrder(Order replacementOrder) {
this.replacementOrder = replacementOrder;
}
}

View File

@ -7,16 +7,19 @@ import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.SecondaryTable;
/**
* @author Emmanuel Bernard
*/
@Entity
@SecondaryTable(name="CLIENT_EXTENSION")
public class Client {
private Integer id;
private String name;
private Address address;
private Address secondaryAddress;
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "ADDRESS_ID")
@ -28,6 +31,16 @@ public class Client {
this.address = address;
}
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "SECONDARY_ADDRESS_ID", table="CLIENT_EXTENSION")
public Address getSecondaryAddress() {
return secondaryAddress;
}
public void setSecondaryAddress(Address secondaryAddress) {
this.secondaryAddress = secondaryAddress;
}
@Id
@GeneratedValue
public Integer getId() {

View File

@ -108,6 +108,31 @@ public class OneToOneTest extends TestCase {
s.close();
}
public void testOneToOneWithExplicitSecondaryTableFk() throws Exception {
Client c = new Client();
Address a = new Address();
a.setCity( "Paris" );
c.setName( "Emmanuel" );
c.setSecondaryAddress( a );
Session s;
Transaction tx;
s = openSession();
tx = s.beginTransaction();
s.persist( c );
tx.commit();
s.close();
s = openSession();
tx = s.beginTransaction();
c = ( Client ) s.get( Client.class, c.getId() );
assertNotNull( c );
assertNotNull( c.getSecondaryAddress() );
assertEquals( "Paris", c.getSecondaryAddress().getCity() );
tx.commit();
s.close();
}
public void testUnidirectionalTrueOneToOne() throws Exception {
Body b = new Body();
Heart h = new Heart();