Skip to content

Commit

Permalink
Add converter to jpa-listeners-injection, as that breaks older versio…
Browse files Browse the repository at this point in the history
…ns of eclipselink
  • Loading branch information
pdudits committed Mar 25, 2019
1 parent 53e7772 commit b938c99
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.javaee7.jpa.listeners;

/**
* @author Patrik Dudits
*/
public enum Language {
ENGLISH, GERMAN;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.javaee7.jpa.listeners;

import javax.persistence.AttributeConverter;
import javax.persistence.Converter;

/**
* The presence of a converter causes injection to fail in Eclipselink 2.7.4
* @author Patrik Dudits
*/
@Converter(autoApply = true)
public class LanguageConverter implements AttributeConverter<Language, String> {
@Override
public String convertToDatabaseColumn(Language attribute) {
if (attribute == null) {
return "Unknown";
}
switch (attribute) {
case ENGLISH:
return "en";
case GERMAN:
return "de";
}
return null;
}

@Override
public Language convertToEntityAttribute(String dbData) {
if (dbData == null) {
return null;
}
switch (dbData) {
case "en":
return Language.ENGLISH;
case "de":
return Language.GERMAN;
default:
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public class Movie implements Serializable {
@Transient
private Integer rating;

private Language language;

public Movie() {
}

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

0 comments on commit b938c99

Please sign in to comment.