From 818987751e31fe8408d88291e5a3e119710a64c4 Mon Sep 17 00:00:00 2001 From: "David M. Carr" Date: Thu, 24 Feb 2011 17:14:08 -0500 Subject: [PATCH 1/2] HHH-5977 Add a couple additional unit tests for when you use a @JoinColumn with a secondary table specified. --- .../annotations/manytoone/ManyToOneTest.java | 20 +++++++++++++++ .../test/annotations/manytoone/OrderLine.java | 13 ++++++++++ .../test/annotations/onetoone/Client.java | 13 ++++++++++ .../annotations/onetoone/OneToOneTest.java | 25 +++++++++++++++++++ 4 files changed, 71 insertions(+) diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/manytoone/ManyToOneTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/manytoone/ManyToOneTest.java index f99a403405..de749ad461 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/manytoone/ManyToOneTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/manytoone/ManyToOneTest.java @@ -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(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/manytoone/OrderLine.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/manytoone/OrderLine.java index 22fc79374c..1b8ed9517a 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/manytoone/OrderLine.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/manytoone/OrderLine.java @@ -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; + } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/onetoone/Client.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/onetoone/Client.java index 44c0a2b456..79c64c1c00 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/onetoone/Client.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/onetoone/Client.java @@ -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() { diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/onetoone/OneToOneTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/onetoone/OneToOneTest.java index a47bb96a90..7a97a0df75 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/onetoone/OneToOneTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/onetoone/OneToOneTest.java @@ -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(); From 48c4db0b579ddd7966bf85b0a90cffcab3fb29c1 Mon Sep 17 00:00:00 2001 From: Strong Liu Date: Fri, 4 Mar 2011 23:15:05 +0800 Subject: [PATCH 2/2] HHH-5707 Deprecated DomainObjectCollection.allObjects(), TaskCollection.allTasks() and PluginCollection.allPlugins(). These are replaced by DomainObjectCollection.all(). --- .../hibernate/build/gradle/upload/AuthenticationHandler.java | 2 +- .../build/gradle/upload/UploadAuthenticationManager.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/buildSrc/src/main/java/org/hibernate/build/gradle/upload/AuthenticationHandler.java b/buildSrc/src/main/java/org/hibernate/build/gradle/upload/AuthenticationHandler.java index c9e0202443..955caf39d2 100644 --- a/buildSrc/src/main/java/org/hibernate/build/gradle/upload/AuthenticationHandler.java +++ b/buildSrc/src/main/java/org/hibernate/build/gradle/upload/AuthenticationHandler.java @@ -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() { public void execute(MavenDeployer deployer) { final RemoteRepository repository = deployer.getRepository(); diff --git a/buildSrc/src/main/java/org/hibernate/build/gradle/upload/UploadAuthenticationManager.java b/buildSrc/src/main/java/org/hibernate/build/gradle/upload/UploadAuthenticationManager.java index 73d29a1c10..2c8909fece 100644 --- a/buildSrc/src/main/java/org/hibernate/build/gradle/upload/UploadAuthenticationManager.java +++ b/buildSrc/src/main/java/org/hibernate/build/gradle/upload/UploadAuthenticationManager.java @@ -43,7 +43,7 @@ public class UploadAuthenticationManager implements Plugin { // code for just that. final AuthenticationProviderRegistry registry = new AuthenticationProviderRegistry(); - project.getTasks().withType( Upload.class ).allTasks( + project.getTasks().withType( Upload.class ).all( new Action() { @Override public void execute(final Upload uploadTask) {