Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.6/apache-maven-3.8.6-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.3.2/maven-wrapper-3.3.2.jar
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.Arrays;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.hibernate4.Hibernate4Module;

import static org.junit.jupiter.api.Assertions.fail;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.json.JsonMapper;
import com.fasterxml.jackson.datatype.hibernate4.data.Customer;
import com.fasterxml.jackson.datatype.hibernate4.data.Payment;
import org.hibernate.Hibernate;
Expand Down Expand Up @@ -37,10 +38,9 @@ public void tearDown() throws Exception {
// [Issue#93], backwards compatible case
@Test
public void testNoReplacePersistentCollection() throws Exception {
final ObjectMapper mapper = new ObjectMapper()
.registerModule(new Hibernate4Module()
final ObjectMapper mapper = hibernateMapper(new Hibernate4Module()
.configure(Hibernate4Module.Feature.FORCE_LAZY_LOADING, true)
).enableDefaultTyping();
);

Customer customer = em.find(Customer.class, 103);
assertFalse(Hibernate.isInitialized(customer.getPayments()));
Expand All @@ -60,7 +60,7 @@ public void testNoReplacePersistentCollection() throws Exception {

boolean exceptionThrown = false;
try {
Map<?, ?> stuff = mapper.readValue(json, Map.class);
/*Map<?, ?> stuff =*/ mapper.readValue(json, Map.class);
} catch (JsonMappingException e) {
exceptionThrown = true;
}
Expand All @@ -70,11 +70,9 @@ public void testNoReplacePersistentCollection() throws Exception {
// [Issue#93], backwards compatible case
@Test
public void testReplacePersistentCollection() throws Exception {
final ObjectMapper mapper = new ObjectMapper()
.registerModule(new Hibernate4Module()
final ObjectMapper mapper = hibernateMapper(new Hibernate4Module()
.configure(Hibernate4Module.Feature.FORCE_LAZY_LOADING, true)
.configure(Hibernate4Module.Feature.REPLACE_PERSISTENT_COLLECTIONS, true)
).enableDefaultTyping();
.configure(Hibernate4Module.Feature.REPLACE_PERSISTENT_COLLECTIONS, true));

Customer customer = em.find(Customer.class, 103);
assertFalse(Hibernate.isInitialized(customer.getPayments()));
Expand All @@ -99,7 +97,7 @@ public void testReplacePersistentCollection() throws Exception {

boolean issue94failed = false;
try {
Map<?, ?> stuff = mapper.readValue(json, Map.class);
/* Map<?, ?> stuff =*/ mapper.readValue(json, Map.class);
} catch (JsonMappingException e) {
issue94failed = true;
}
Expand All @@ -112,4 +110,11 @@ public void testReplacePersistentCollection() throws Exception {
// assertTrue(stuff.containsKey("orders"));
// assertNull(stuff.get("orderes"));
}

private ObjectMapper hibernateMapper(Hibernate4Module module) {
return JsonMapper.builder()
.addModule(module)
.build()
.enableDefaultTyping();
}
}
42 changes: 21 additions & 21 deletions hibernate4/src/test/resources/classicmodels.sql
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ CREATE TABLE `classicmodels`.`Customer` (
`contactFirstName` varchar(50) NOT NULL,
`phone` varchar(50) NOT NULL,
`addressLine1` varchar(50) NOT NULL,
`addressLine2` varchar(50) DEFAULT NULL,
`addressLine2` varchar(50),
`city` varchar(50) NOT NULL,
`state` varchar(50) DEFAULT NULL,
`postalCode` varchar(15) DEFAULT NULL,
`state` varchar(50),
`postalCode` varchar(15) ,
`country` varchar(50) NOT NULL,
`salesRepEmployeeNumber` int(11) DEFAULT NULL,
`creditLimit` double DEFAULT NULL,
`missingProductCode` varchar(50) NULL,
`salesRepEmployeeNumber` int(11),
`creditLimit` double,
`missingProductCode` varchar(50),
PRIMARY KEY (`customerNumber`)
) DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
);
INSERT INTO `classicmodels`.`Customer` (`customerNumber`,`customerName`,`contactLastName`,`contactFirstName`,`phone`,`addressLine1`,`addressLine2`,`city`,`state`,`postalCode`,`country`,`salesRepEmployeeNumber`,`creditLimit`) VALUES
(103,'Atelier graphique','Schmitt','Carine ','40.32.2555','54, rue Royale',NULL,'Nantes',NULL,'44000','France',1370,21000),
(112,'Signal Gift Stores','King','Sue','7025551838','8489 Strong St.',NULL,'Las Vegas','NV','83030','USA',1166,71800),
Expand Down Expand Up @@ -168,7 +168,7 @@ INSERT INTO `classicmodels`.`Customer` (`customerNumber`,`customerName`,`contact
(496,'Kellys Gift Shop','Snowden','Tony','+64 9 5555500','Arenales 1938 3A',NULL,'Auckland ',NULL,'','New Zealand',1612,110000);
INSERT INTO `classicmodels`.`Customer` (`customerNumber`,`customerName`,`contactLastName`,`contactFirstName`,`phone`,`addressLine1`,`addressLine2`,`city`,`state`,`postalCode`,`country`,`salesRepEmployeeNumber`,`creditLimit`, `missingProductCode`) VALUES
(500,'Customer with valid product','Schmitt','Carine ','40.32.2555','54, rue Royale',NULL,'Nantes',NULL,'44000','France',1370,21000, 'S10_1678'),
(501,'Customer with invalid product','Schmitt','Carine ','40.32.2555','54, rue Royale',NULL,'Nantes',NULL,'44000','France',1370,21000, 'X10_1678'),
(501,'Customer with invalid product','Schmitt','Carine ','40.32.2555','54, rue Royale',NULL,'Nantes',NULL,'44000','France',1370,21000, 'X10_1678');

DROP TABLE IF EXISTS `classicmodels`.`Employee`;
CREATE TABLE `classicmodels`.`Employee` (
Expand All @@ -178,10 +178,10 @@ CREATE TABLE `classicmodels`.`Employee` (
`extension` varchar(10) NOT NULL,
`email` varchar(100) NOT NULL,
`officeCode` varchar(50) NOT NULL,
`reportsTo` int(11) DEFAULT NULL,
`reportsTo` int(11) ,
`jobTitle` varchar(50) NOT NULL,
PRIMARY KEY (`employeeNumber`)
) DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
);
INSERT INTO `classicmodels`.`Employee` (`employeeNumber`,`lastName`,`firstName`,`extension`,`email`,`officeCode`,`reportsTo`,`jobTitle`) VALUES
(1002,'Murphy','Diane','x5800','[email protected]','1',NULL,'President'),
(1056,'Patterson','Mary','x4611','[email protected]','1',1002,'VP Sales'),
Expand Down Expand Up @@ -213,13 +213,13 @@ CREATE TABLE `classicmodels`.`Office` (
`city` varchar(50) NOT NULL,
`phone` varchar(50) NOT NULL,
`addressLine1` varchar(50) NOT NULL,
`addressLine2` varchar(50) DEFAULT NULL,
`state` varchar(50) DEFAULT NULL,
`addressLine2` varchar(50) ,
`state` varchar(50) ,
`country` varchar(50) NOT NULL,
`postalCode` varchar(10) NOT NULL,
`territory` varchar(10) NOT NULL,
PRIMARY KEY (`officeCode`)
) DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
);
INSERT INTO `classicmodels`.`Office` (`officeCode`,`city`,`phone`,`addressLine1`,`addressLine2`,`state`,`country`,`postalCode`,`territory`) VALUES
('1','San Francisco','+1 650 219 4782','100 Market Street','Suite 300','CA','USA','94080','NA'),
('2','Boston','+1 215 837 0825','1550 Court Place','Suite 102','MA','USA','02107','NA'),
Expand All @@ -234,12 +234,12 @@ CREATE TABLE `classicmodels`.`Order` (
`orderNumber` int(11) NOT NULL,
`orderDate` datetime NOT NULL,
`requiredDate` datetime NOT NULL,
`shippedDate` datetime DEFAULT NULL,
`shippedDate` datetime ,
`status` varchar(15) NOT NULL,
`comments` text,
`customerNumber` int(11) NOT NULL,
PRIMARY KEY (`orderNumber`)
) DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
);
INSERT INTO `classicmodels`.`Order` (`orderNumber`,`orderDate`,`requiredDate`,`shippedDate`,`status`,`comments`,`customerNumber`) VALUES
(10100,'2003-01-06 00:00:00','2003-01-13 00:00:00','2003-01-10 00:00:00','Shipped',NULL,363),
(10101,'2003-01-09 00:00:00','2003-01-18 00:00:00','2003-01-11 00:00:00','Shipped','Check on availability.',128),
Expand Down Expand Up @@ -576,7 +576,7 @@ CREATE TABLE `classicmodels`.`OrderDetail` (
`priceEach` double NOT NULL,
`orderLineNumber` smallint(6) NOT NULL,
PRIMARY KEY (`orderNumber`,`productCode`)
) DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
);
INSERT INTO `classicmodels`.`OrderDetail` (`orderNumber`,`productCode`,`quantityOrdered`,`priceEach`,`orderLineNumber`) VALUES
(10100,'S18_1749',30,171.7,3),
(10100,'S18_2248',50,67.8,2),
Expand Down Expand Up @@ -3583,7 +3583,7 @@ CREATE TABLE `classicmodels`.`Payment` (
`paymentDate` datetime NOT NULL,
`amount` double NOT NULL,
PRIMARY KEY (`customerNumber`,`checkNumber`)
) DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
);
INSERT INTO `classicmodels`.`Payment` (`customerNumber`,`checkNumber`,`paymentDate`,`amount`) VALUES
(103,'HQ336336','2004-10-19 00:00:00',5307.98),
(103,'JM555205','2003-06-05 00:00:00',16560.3),
Expand Down Expand Up @@ -3870,7 +3870,7 @@ CREATE TABLE `classicmodels`.`Product` (
`buyPrice` double NOT NULL,
`MSRP` double NOT NULL,
PRIMARY KEY (`productCode`)
) DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
);
INSERT INTO `classicmodels`.`Product` (`productCode`,`productName`,`productLine`,`productScale`,`productVendor`,`productDescription`,`quantityInStock`,`buyPrice`,`MSRP`) VALUES
('S10_1678','1969 Harley Davidson Ultimate Chopper','Motorcycles','1:10','Min Lin Diecast','This replica features working kickstand, front suspension, gear-shift lever, footbrake lever, drive chain, wheels and steering. All parts are particularly delicate due to their precise scale and require special care and attention.',7933,48.81,95.7),
('S10_1949','1952 Alpine Renault 1300','Classic Cars','1:10','Classic Metal Creations','Turnable front wheels; steering function; detailed interior; detailed engine; opening hood; opening trunk; opening doors; and detailed chassis.',7305,98.58,214.3),
Expand Down Expand Up @@ -3989,7 +3989,7 @@ CREATE TABLE `classicmodels`.`Contrato` (
`id` numeric(10) NOT NULL,
`numero_contrato` varchar(50) NOT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
);
INSERT INTO `classicmodels`.`Contrato` (`id`,`numero_contrato`) VALUES
(1, '100001-9');

Expand All @@ -3999,7 +3999,7 @@ CREATE TABLE `classicmodels`.`Parcela` (
`numero_parcela` numeric(10) NOT NULL,
`contrato_id` numeric(10) NOT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
);
INSERT INTO `classicmodels`.`Parcela` (`id`,`numero_parcela`,`contrato_id`) VALUES
(1, 1, 1);

Expand All @@ -4010,7 +4010,7 @@ CREATE TABLE `classicmodels`.`Liquidacao` (
`contrato_id` numeric(10) NOT NULL,
`parcela_id` numeric(10) NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
);
INSERT INTO `classicmodels`.`Liquidacao` (`id`,`valor_total`,`contrato_id`, `parcela_id`) VALUES
(1, 10000, 1, 1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectMapper.DefaultTyping;
import com.fasterxml.jackson.databind.json.JsonMapper;
import com.fasterxml.jackson.datatype.hibernate5.jakarta.data.Customer;
import com.fasterxml.jackson.datatype.hibernate5.jakarta.data.Payment;

Expand Down Expand Up @@ -39,10 +40,9 @@ public void tearDown() throws Exception {
// [Issue#93], backwards compatible case
@Test
public void testNoReplacePersistentCollection() throws Exception {
final ObjectMapper mapper = new ObjectMapper()
.registerModule(new Hibernate5JakartaModule()
final ObjectMapper mapper = hibernateMapper(new Hibernate5JakartaModule()
.configure(Hibernate5JakartaModule.Feature.FORCE_LAZY_LOADING, true)
).enableDefaultTyping(DefaultTyping.NON_FINAL);
);

Customer customer = em.find(Customer.class, 103);
assertFalse(Hibernate.isInitialized(customer.getPayments()));
Expand All @@ -63,11 +63,10 @@ public void testNoReplacePersistentCollection() throws Exception {
// [Issue#93], backwards compatible case
@Test
public void testReplacePersistentCollection() throws Exception {
final ObjectMapper mapper = new ObjectMapper()
.registerModule(new Hibernate5JakartaModule()
final ObjectMapper mapper = hibernateMapper(new Hibernate5JakartaModule()
.configure(Hibernate5JakartaModule.Feature.FORCE_LAZY_LOADING, true)
.configure(Hibernate5JakartaModule.Feature.REPLACE_PERSISTENT_COLLECTIONS, true)
).enableDefaultTyping(DefaultTyping.NON_FINAL);
);

Customer customer = em.find(Customer.class, 103);
assertFalse(Hibernate.isInitialized(customer.getPayments()));
Expand All @@ -86,4 +85,11 @@ public void testReplacePersistentCollection() throws Exception {
// assertTrue(stuff.containsKey("orders"));
// assertNull(stuff.get("orderes"));
}

private ObjectMapper hibernateMapper(Hibernate5JakartaModule module) {
return JsonMapper.builder()
.addModule(module)
.build()
.enableDefaultTyping(DefaultTyping.NON_FINAL);
}
}
Loading