Skip to content

Commit

Permalink
Failing test for SqlServer
Browse files Browse the repository at this point in the history
  • Loading branch information
rPraml committed Jun 19, 2023
1 parent 9fc1bec commit ca3c02b
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
52 changes: 52 additions & 0 deletions ebean-test/src/test/java/org/tests/json/TestDbJsonLength.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.tests.json;

import io.ebean.DB;
import io.ebean.DataIntegrityException;
import org.assertj.core.api.SoftAssertions;
import org.junit.jupiter.api.Test;
import org.tests.model.json.EBasicJsonMap;

import java.util.Map;

class TestDbJsonLength {


/**
* The property 'EBasicJsonMap.content' is annotated with @DbJson(length=5000). So we assume, that we cannot save Json-objects
* where the serialized form exceed that limit and we would expect an error on save.
* The length check works for platforms like h2, as H2 uses a 'varchar(5000)'. So it is impossible to save such long jsons,
* but it won't work for SqlServer, as here 'nvarchar(max)' is used. No validation happens at DB level and you might get very
* large Json objects in your database. This mostly happens unintentionally (programming error, misconfiguration)
* So they are in the database and they cannot be accessed by ebean any more, because there are new limits in Jackson:
* - Max 5 Meg per string in 2.15.0
* - Max 20 Meg per string in 2.15.1
* see https://github.com/FasterXML/jackson-core/issues/1014
*/
@Test
void testLongString() {
// s is so big, that it could not be deserialized by jackson
String s = new String(new char[20_000_001]).replace('\0', 'x');

EBasicJsonMap bean = new EBasicJsonMap();
bean.setName("b1");
bean.setContent(Map.of("string", s));

SoftAssertions softly = new SoftAssertions();

softly.assertThatThrownBy(() -> {
DB.save(bean);
}).isInstanceOf(DataIntegrityException.class);


if (bean.getId() != null) {
// we expect, that we could NOT save the bean, but this is not true for sqlServer.
// we will get a javax.persistence.PersistenceException: Error loading on org.tests.model.json.EBasicJsonMap.content
// when we try to load the bean back from DB
DB.find(EBasicJsonMap.class, bean.getId());
}

softly.assertAll();

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class EBasicJsonMap {

String name;

@DbJson
@DbJson(length = 5000)
Map<String, Object> content;

@OneToMany(mappedBy = "owner", cascade = CascadeType.ALL)
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<nexus.staging.keepStagingRepositoryOnFailure>true</nexus.staging.keepStagingRepositoryOnFailure>
<nexus.staging.skipStagingRepositoryClose>true</nexus.staging.skipStagingRepositoryClose>
<nexus.staging.autoReleaseAfterClose>false</nexus.staging.autoReleaseAfterClose>
<jackson.version>2.15.0</jackson.version>
<jackson.version>2.15.2</jackson.version>
<h2database.version>2.1.214</h2database.version>
<ebean-persistence-api.version>3.0</ebean-persistence-api.version>
<ebean-types.version>3.0</ebean-types.version>
Expand Down

0 comments on commit ca3c02b

Please sign in to comment.