You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by Erdbeerheld1990 <An...@gmx.de> on 2020/02/28 14:38:45 UTC
Unable to use JPA Attribute converters in karaf
Hello,
we are using karaf version 4.2.7 with blueprint. Now the first time we want
to implement an Attribute Converter
<https://www.baeldung.com/jpa-attribute-converters> from JPA in order to
convert the string content of a column to an Object.
@Converter(autoApply = true)
public class DynamicViewConfigurationConverterJson implements
AttributeConverter<DynamicViewConfiguration, String> {
private final static ObjectMapper objectMapper = new ObjectMapper();
@Override
public String convertToDatabaseColumn(DynamicViewConfiguration
dynamicViewConfiguration) {
try {
return objectMapper.writeValueAsString(dynamicViewConfiguration);
} catch (JsonProcessingException ex) {
return null;
}
}
@Override
public DynamicViewConfiguration convertToEntityAttribute(String dbData) {
try {
return objectMapper.readValue(dbData, DynamicViewConfiguration.class);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
And this is my entity:
@Entity
@Table(name = "CAIS_DYNAMIC_VIEW")
public class DynamicView {
private Long id;
private String viewName;
private String detailViewRoute;
private String translationKey;
private String viewCategory;
private DynamicViewConfiguration viewConfiguration;
public DynamicView() {
}
@Id
@GenericGenerator(name = "id_generator", strategy =
"com.cedros.cais.persistence.generator.IdGenerator")
@GeneratedValue(generator = "id_generator")
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Column(name = "VIEW_NAME", nullable = false)
public String getViewName() {
return viewName;
}
public void setViewName(String viewName) {
this.viewName = viewName;
}
@Column(name = "DETAIL_VIEW_ROUTE")
public String getDetailViewRoute() {
return detailViewRoute;
}
public void setDetailViewRoute(String detailViewRoute) {
this.detailViewRoute = detailViewRoute;
}
@Column(name = "TRANSLATION_KEY", nullable = false)
public String getTranslationKey() {
return translationKey;
}
public void setTranslationKey(String translationKey) {
this.translationKey = translationKey;
}
@Column(name = "VIEW_CATEGORY")
public String getViewCategory() {
return viewCategory;
}
public void setViewCategory(String viewCategory) {
this.viewCategory = viewCategory;
}
@Column(name = "VIEW_CONFIGURATION", nullable = false)
@Convert( converter = DynamicViewConfigurationConverterJson.class)
public DynamicViewConfiguration getViewConfiguration() {
return viewConfiguration;
}
public void setViewConfiguration(DynamicViewConfiguration
viewConfiguration) {
this.viewConfiguration = viewConfiguration;
}
}
My Unit tests are working fine from spring context. But when i keep the
@Convert annotation and run it in karaf, my DAOs are not starting. They are
waiting for the persistence-Context and fail after some time - Declaritive
Services:
Status: GracePeriod
Blueprint
28.02.20 15:30
Missing dependencies:
(&(osgi.unit.name=caisPersistenceUnit)(objectClass=javax.persistence.EntityManager))
Declarative Services
When i remove the @Convert annotation it is not complaining, but then of
course my attribute converter has not any effect. I would be very pleased
for your help.
Best regards,
Andreas
--
Sent from: http://karaf.922171.n3.nabble.com/Karaf-User-f930749.html
Re: Unable to use JPA Attribute converters in karaf
Posted by Erdbeerheld1990 <An...@gmx.de>.
Hello,
i fixed the issue by using field annotation on the entity instead on the
getter methods. Then i was able to correctly use my converter with the
@Convert annotation. I don't know why, but it worked.
Best regards,
Andy
--
Sent from: http://karaf.922171.n3.nabble.com/Karaf-User-f930749.html
Re: Unable to use JPA Attribute converters in karaf
Posted by Erdbeerheld1990 <An...@gmx.de>.
Hi,
yes of course. Seems to be only one feature.
karaf@root()> feature:list | grep jpa
camel-jpa | 2.18.2 |
| Uninstalled | camel-2.18.2 |
openjpa3 | 3.0.0 |
| Uninstalled | enterprise-4.2.7 | OpenJPA engine support
deltaspike-jpa | 1.3.0 |
| Uninstalled | org.ops4j.pax.cdi-1.0.0.RC1 | Apache Deltaspike jpa
support
openjpa | 3.0.0 |
| Uninstalled | openjpa-3.0.0 | Apache OpenJPA 3
persistence engine support
deltaspike-jpa | 1.8.1 |
| Uninstalled | org.ops4j.pax.cdi-1.1.1 | Apache Deltaspike jpa
support
jpa | 2.7.2 |
| Started | aries-jpa-2.7.2 | OSGi Persistence
Container
Best regards
Andreas
--
Sent from: http://karaf.922171.n3.nabble.com/Karaf-User-f930749.html
Re: Unable to use JPA Attribute converters in karaf
Posted by Jean-Baptiste Onofre <jb...@nanthrax.net>.
Hi,
Can you share the features you have installed about jpa ?
Regards
JB
> Le 28 févr. 2020 à 15:38, Erdbeerheld1990 <An...@gmx.de> a écrit :
>
> Hello,
>
> we are using karaf version 4.2.7 with blueprint. Now the first time we want
> to implement an Attribute Converter
> <https://www.baeldung.com/jpa-attribute-converters> from JPA in order to
> convert the string content of a column to an Object.
>
> @Converter(autoApply = true)
> public class DynamicViewConfigurationConverterJson implements
> AttributeConverter<DynamicViewConfiguration, String> {
>
> private final static ObjectMapper objectMapper = new ObjectMapper();
>
> @Override
> public String convertToDatabaseColumn(DynamicViewConfiguration
> dynamicViewConfiguration) {
> try {
> return objectMapper.writeValueAsString(dynamicViewConfiguration);
> } catch (JsonProcessingException ex) {
> return null;
> }
> }
>
> @Override
> public DynamicViewConfiguration convertToEntityAttribute(String dbData) {
> try {
> return objectMapper.readValue(dbData, DynamicViewConfiguration.class);
> } catch (IOException e) {
> throw new RuntimeException(e);
> }
> }
>
> }
>
> And this is my entity:
>
> @Entity
> @Table(name = "CAIS_DYNAMIC_VIEW")
> public class DynamicView {
> private Long id;
> private String viewName;
> private String detailViewRoute;
> private String translationKey;
> private String viewCategory;
> private DynamicViewConfiguration viewConfiguration;
>
> public DynamicView() {
> }
>
> @Id
> @GenericGenerator(name = "id_generator", strategy =
> "com.cedros.cais.persistence.generator.IdGenerator")
> @GeneratedValue(generator = "id_generator")
> public Long getId() {
> return id;
> }
>
> public void setId(Long id) {
> this.id = id;
> }
>
> @Column(name = "VIEW_NAME", nullable = false)
> public String getViewName() {
> return viewName;
> }
>
> public void setViewName(String viewName) {
> this.viewName = viewName;
> }
>
> @Column(name = "DETAIL_VIEW_ROUTE")
> public String getDetailViewRoute() {
> return detailViewRoute;
> }
>
> public void setDetailViewRoute(String detailViewRoute) {
> this.detailViewRoute = detailViewRoute;
> }
>
> @Column(name = "TRANSLATION_KEY", nullable = false)
> public String getTranslationKey() {
> return translationKey;
> }
>
> public void setTranslationKey(String translationKey) {
> this.translationKey = translationKey;
> }
>
> @Column(name = "VIEW_CATEGORY")
> public String getViewCategory() {
> return viewCategory;
> }
>
> public void setViewCategory(String viewCategory) {
> this.viewCategory = viewCategory;
> }
>
> @Column(name = "VIEW_CONFIGURATION", nullable = false)
> @Convert( converter = DynamicViewConfigurationConverterJson.class)
> public DynamicViewConfiguration getViewConfiguration() {
> return viewConfiguration;
> }
>
> public void setViewConfiguration(DynamicViewConfiguration
> viewConfiguration) {
> this.viewConfiguration = viewConfiguration;
> }
> }
>
>
> My Unit tests are working fine from spring context. But when i keep the
> @Convert annotation and run it in karaf, my DAOs are not starting. They are
> waiting for the persistence-Context and fail after some time - Declaritive
> Services:
>
> Status: GracePeriod
> Blueprint
> 28.02.20 15:30
> Missing dependencies:
> (&(osgi.unit.name=caisPersistenceUnit)(objectClass=javax.persistence.EntityManager))
> Declarative Services
>
>
> When i remove the @Convert annotation it is not complaining, but then of
> course my attribute converter has not any effect. I would be very pleased
> for your help.
>
> Best regards,
> Andreas
>
>
>
> --
> Sent from: http://karaf.922171.n3.nabble.com/Karaf-User-f930749.html