Added example-code for hibernate-bug HHH-9615 as additional test-case
authorKai Moritz <kai@juplo.de>
Sun, 13 Nov 2016 14:26:18 +0000 (15:26 +0100)
committerKai Moritz <kai@juplo.de>
Sun, 13 Nov 2016 16:37:15 +0000 (17:37 +0100)
See: https://hibernate.atlassian.net/browse/HHH-9615

src/it/hibernate-lob-converter-bug/pom.xml [new file with mode: 0644]
src/it/hibernate-lob-converter-bug/src/test/java/io/blep/LobConverterTest.java [new file with mode: 0644]
src/it/hibernate-lob-converter-bug/src/test/java/io/blep/MyEntity.java [new file with mode: 0644]
src/it/hibernate-lob-converter-bug/src/test/resources/META-INF/persistence.xml [new file with mode: 0644]

diff --git a/src/it/hibernate-lob-converter-bug/pom.xml b/src/it/hibernate-lob-converter-bug/pom.xml
new file mode 100644 (file)
index 0000000..b2a76e7
--- /dev/null
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>io.blep</groupId>
+    <artifactId>hibernate-lob-converter-bug</artifactId>
+    <version>1.0-SNAPSHOT</version>
+    <repositories>
+        <repository>
+            <id>jboss-maven2-release-repository</id>
+            <name>JBoss</name>
+            <url>https://repository.jboss.org/nexus/content/repositories/snapshots/</url>
+            <snapshots>
+                <enabled>true</enabled>
+            </snapshots>
+        </repository>
+    </repositories>
+
+    <dependencies>
+        <dependency>
+            <groupId>com.h2database</groupId>
+            <artifactId>h2</artifactId>
+            <version>1.3.168</version>
+        </dependency>
+
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.11</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.hibernate</groupId>
+            <artifactId>hibernate-entitymanager</artifactId>
+            <version>5.0.0-SNAPSHOT</version>
+        </dependency>
+
+    </dependencies>
+
+
+
+</project>
\ No newline at end of file
diff --git a/src/it/hibernate-lob-converter-bug/src/test/java/io/blep/LobConverterTest.java b/src/it/hibernate-lob-converter-bug/src/test/java/io/blep/LobConverterTest.java
new file mode 100644 (file)
index 0000000..b08b858
--- /dev/null
@@ -0,0 +1,22 @@
+package io.blep;
+
+import org.junit.Test;
+
+import javax.persistence.*;
+
+/**
+ * @author blep
+ */
+public class LobConverterTest {
+
+    @Test
+    public void testName() throws Exception {
+        final EntityManagerFactory emf = Persistence.createEntityManagerFactory("samplePU");
+
+        final EntityManager em = emf.createEntityManager();
+
+        em.getTransaction().begin();
+        em.persist(new MyEntity());
+        em.getTransaction().commit();
+    }
+}
diff --git a/src/it/hibernate-lob-converter-bug/src/test/java/io/blep/MyEntity.java b/src/it/hibernate-lob-converter-bug/src/test/java/io/blep/MyEntity.java
new file mode 100644 (file)
index 0000000..0907809
--- /dev/null
@@ -0,0 +1,48 @@
+package io.blep;
+
+import javax.persistence.*;
+
+/**
+ * @author blep
+ */
+@Entity
+public class MyEntity {
+    @Id
+    @GeneratedValue(strategy = GenerationType.AUTO)
+    private Integer id;
+
+    @Convert(converter = MyConverter.class)
+    @Lob
+    private String status;
+
+    @Converter
+    public static class MyConverter implements AttributeConverter<String, Integer> {
+
+        @Override
+        public Integer convertToDatabaseColumn(String attribute) {
+            return attribute.length();
+        }
+
+        @Override
+        public String convertToEntityAttribute(Integer dbData) {
+            return "";
+        }
+    }
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public String getStatus() {
+        return status;
+    }
+
+    public void setStatus(String status) {
+        this.status = status;
+    }
+
+}
diff --git a/src/it/hibernate-lob-converter-bug/src/test/resources/META-INF/persistence.xml b/src/it/hibernate-lob-converter-bug/src/test/resources/META-INF/persistence.xml
new file mode 100644 (file)
index 0000000..78e416d
--- /dev/null
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence" version="2.1">
+
+    <persistence-unit name="samplePU" transaction-type="RESOURCE_LOCAL">
+        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
+        <class>io.blep.MyEntity</class>
+        <properties>
+            <property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
+            <property name="javax.persistence.schema-generation.scripts.drop-target" value="sampleDrop.ddl"/>
+            <property name="javax.persistence.jdbc.driver" value="org.h2.Driver"/>
+            <property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:sampleDB"/>
+        </properties>
+    </persistence-unit>
+</persistence>