Skip to content

Commit b938c99

Browse files
committed
Add converter to jpa-listeners-injection, as that breaks older versions of eclipselink
1 parent 53e7772 commit b938c99

File tree

4 files changed

+51
-1
lines changed

4 files changed

+51
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.javaee7.jpa.listeners;
2+
3+
/**
4+
* @author Patrik Dudits
5+
*/
6+
public enum Language {
7+
ENGLISH, GERMAN;
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package org.javaee7.jpa.listeners;
2+
3+
import javax.persistence.AttributeConverter;
4+
import javax.persistence.Converter;
5+
6+
/**
7+
* The presence of a converter causes injection to fail in Eclipselink 2.7.4
8+
* @author Patrik Dudits
9+
*/
10+
@Converter(autoApply = true)
11+
public class LanguageConverter implements AttributeConverter<Language, String> {
12+
@Override
13+
public String convertToDatabaseColumn(Language attribute) {
14+
if (attribute == null) {
15+
return "Unknown";
16+
}
17+
switch (attribute) {
18+
case ENGLISH:
19+
return "en";
20+
case GERMAN:
21+
return "de";
22+
}
23+
return null;
24+
}
25+
26+
@Override
27+
public Language convertToEntityAttribute(String dbData) {
28+
if (dbData == null) {
29+
return null;
30+
}
31+
switch (dbData) {
32+
case "en":
33+
return Language.ENGLISH;
34+
case "de":
35+
return Language.GERMAN;
36+
default:
37+
return null;
38+
}
39+
}
40+
}

jpa/listeners-injection/src/main/java/org/javaee7/jpa/listeners/Movie.java

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ public class Movie implements Serializable {
4141
@Transient
4242
private Integer rating;
4343

44+
private Language language;
45+
4446
public Movie() {
4547
}
4648

Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
CREATE TABLE MOVIE_LISTENER("ID" INTEGER not null primary key, "NAME" VARCHAR(50) not null, "ACTORS" VARCHAR(200) not null)
1+
CREATE TABLE MOVIE_LISTENER("ID" INTEGER not null primary key, "NAME" VARCHAR(50) not null, "ACTORS" VARCHAR(200) not null, "LANGUAGE" VARCHAR(12))
22
CREATE TABLE MOVIE_RATINGS("ID" INTEGER not null primary key, "NAME" VARCHAR(50) not null, "RATING" INTEGER not null)

0 commit comments

Comments
 (0)