Discussion:
Using JPA with Microwave fails
Björn Berg
2017-11-21 20:27:12 UTC
Permalink
Hi,

I have tried to create a small application based on Meecrowave and JPA extension. But when I always try to persist an entity, it fails with a NullPointerException which I cannot really drill down to find the root cause.

First I thought injected EntityManager is null but logging the EntityManager call told me, that it really exists. PersistenceUnitInfoBuilder and DataSource is produced like described on
http://openwebbeans.apache.org/meecrowave/meecrowave-jpa/index.html <http://openwebbeans.apache.org/meecrowave/meecrowave-jpa/index.html>


The called InstrumentDao looks like this:
@ApplicationScoped
@Jpa(transactional = false)
public class InstrumentDao {
@Inject
@Unit(name = "depot")
private EntityManager em;

@Jpa
public void save (Instrument instrument) {
em.merge(instrument);
}


}

The entity Instrument is defined like this:
@Entity
@Table(name = "INSTRUMENT")
public class Instrument implements Serializable {
@Id
private String isin;
private String name;

public Instrument() {

}


}

Stacktrace is like following:
Caused by: java.lang.NullPointerException
at org.apache.meecrowave.jpa.internal.EntityManagerBean.destroy(EntityManagerBean.java:95) ~[meecrowave-jpa-1.1.0.jar:1.1.0]
at org.apache.meecrowave.jpa.internal.EntityManagerBean.destroy(EntityManagerBean.java:29) ~[meecrowave-jpa-1.1.0.jar:1.1.0]
at org.apache.webbeans.component.third.ThirdpartyBeanImpl.destroy(ThirdpartyBeanImpl.java:113) ~[openwebbeans-impl-2.0.1.jar:2.0.1]
at org.apache.meecrowave.jpa.internal.EntityManagerContext$ThreadContext.doDestroy(EntityManagerContext.java:130) ~[meecrowave-jpa-1.1.0.jar:1.1.0]
at org.apache.meecrowave.jpa.internal.EntityManagerContext$ThreadContext.lambda$exit$1(EntityManagerContext.java:140) ~[meecrowave-jpa-1.1.0.jar:1.1.0]
at java.util.HashMap.forEach(HashMap.java:1280) ~[?:1.8.0_77]
at org.apache.meecrowave.jpa.internal.EntityManagerContext$ThreadContext.exit(EntityManagerContext.java:140) ~[meecrowave-jpa-1.1.0.jar:1.1.0]
at org.apache.meecrowave.jpa.internal.EntityManagerContext$ThreadContext.access$300(EntityManagerContext.java:94) ~[meecrowave-jpa-1.1.0.jar:1.1.0]
at org.apache.meecrowave.jpa.internal.EntityManagerContext.exit(EntityManagerContext.java:52) ~[meecrowave-jpa-1.1.0.jar:1.1.0]
at org.apache.meecrowave.jpa.internal.JpaInterceptorBase.inTransaction(JpaInterceptorBase.java:40) ~[meecrowave-jpa-1.1.0.jar:1.1.0]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_77]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_77]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_77]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_77]
at org.apache.webbeans.component.InterceptorBean.intercept(InterceptorBean.java:136) ~[openwebbeans-impl-2.0.1.jar:2.0.1]
at org.apache.webbeans.intercept.InterceptorInvocationContext.proceed(InterceptorInvocationContext.java:65) ~[openwebbeans-impl-2.0.1.jar:2.0.1]
at org.apache.webbeans.intercept.DefaultInterceptorHandler.invoke(DefaultInterceptorHandler.java:139) ~[openwebbeans-impl-2.0.1.jar:2.0.1]
at org.kivio.depot.dao.InstrumentDao$$OwbInterceptProxy0.save(org/kivio/depot/dao/InstrumentDao.java) ~[?:?]
at org.kivio.depot.dao.InstrumentDao$$OwbNormalScopeProxy0.save(org/kivio/depot/dao/InstrumentDao.java) ~[?:?]
at org.kivio.depot.service.DepotService.addInstrument(DepotService.java:69) ~[classes/:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_77]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_77]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_77]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_77]

Someone can give me a hint what I am doing wrong?

Kind regards,
Björn
Romain Manni-Bucau
2017-11-21 22:38:55 UTC
Permalink
Looks like cdi instance is null in this context. Do you have a sample
reproducing it?
Post by Björn Berg
Hi,
I have tried to create a small application based on Meecrowave and JPA
extension. But when I always try to persist an entity, it fails with a
NullPointerException which I cannot really drill down to find the root
cause.
First I thought injected EntityManager is null but logging the
EntityManager call told me, that it really exists.
PersistenceUnitInfoBuilder and DataSource is produced like described on
http://openwebbeans.apache.org/meecrowave/meecrowave-jpa/index.html
@ApplicationScoped
@Jpa(transactional = false)
public class InstrumentDao {
@Inject
@Unit(name = "depot")
private EntityManager em;
@Jpa
public void save (Instrument instrument) {
em.merge(instrument);
}


}
@Entity
@Table(name = "INSTRUMENT")
public class Instrument implements Serializable {
@Id
private String isin;
private String name;
public Instrument() {
}


}
Caused by: java.lang.NullPointerException
at org.apache.meecrowave.jpa.internal.EntityManagerBean.
destroy(EntityManagerBean.java:95) ~[meecrowave-jpa-1.1.0.jar:1.1.0]
at org.apache.meecrowave.jpa.internal.EntityManagerBean.
destroy(EntityManagerBean.java:29) ~[meecrowave-jpa-1.1.0.jar:1.1.0]
at org.apache.webbeans.component.third.ThirdpartyBeanImpl.
destroy(ThirdpartyBeanImpl.java:113) ~[openwebbeans-impl-2.0.1.jar:2.0.1]
at org.apache.meecrowave.jpa.internal.EntityManagerContext$
ThreadContext.doDestroy(EntityManagerContext.java:130)
~[meecrowave-jpa-1.1.0.jar:1.1.0]
at org.apache.meecrowave.jpa.internal.EntityManagerContext$
ThreadContext.lambda$exit$1(EntityManagerContext.java:140)
~[meecrowave-jpa-1.1.0.jar:1.1.0]
at java.util.HashMap.forEach(HashMap.java:1280) ~[?:1.8.0_77]
at org.apache.meecrowave.jpa.internal.EntityManagerContext$
ThreadContext.exit(EntityManagerContext.java:140)
~[meecrowave-jpa-1.1.0.jar:1.1.0]
at org.apache.meecrowave.jpa.internal.EntityManagerContext$
ThreadContext.access$300(EntityManagerContext.java:94)
~[meecrowave-jpa-1.1.0.jar:1.1.0]
at org.apache.meecrowave.jpa.internal.EntityManagerContext.
exit(EntityManagerContext.java:52) ~[meecrowave-jpa-1.1.0.jar:1.1.0]
at org.apache.meecrowave.jpa.internal.JpaInterceptorBase.inTransaction(JpaInterceptorBase.java:40)
~[meecrowave-jpa-1.1.0.jar:1.1.0]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
~[?:1.8.0_77]
at sun.reflect.NativeMethodAccessorImpl.invoke(
NativeMethodAccessorImpl.java:62) ~[?:1.8.0_77]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_77]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_77]
at org.apache.webbeans.component.InterceptorBean.intercept(InterceptorBean.java:136)
~[openwebbeans-impl-2.0.1.jar:2.0.1]
at org.apache.webbeans.intercept.InterceptorInvocationContext.proceed(
InterceptorInvocationContext.java:65) ~[openwebbeans-impl-2.0.1.jar:2.0.1]
at org.apache.webbeans.intercept.DefaultInterceptorHandler.invoke(
DefaultInterceptorHandler.java:139) ~[openwebbeans-impl-2.0.1.jar:2.0.1]
at org.kivio.depot.dao.InstrumentDao$$OwbInterceptProxy0.save(org/
kivio/depot/dao/InstrumentDao.java) ~[?:?]
at org.kivio.depot.dao.InstrumentDao$$OwbNormalScopeProxy0.save(org/
kivio/depot/dao/InstrumentDao.java) ~[?:?]
at org.kivio.depot.service.DepotService.addInstrument(DepotService.java:69) ~[classes/:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
~[?:1.8.0_77]
at sun.reflect.NativeMethodAccessorImpl.invoke(
NativeMethodAccessorImpl.java:62) ~[?:1.8.0_77]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_77]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_77]
Someone can give me a hint what I am doing wrong?
Kind regards,
Björn
Björn Berg
2017-11-22 21:00:40 UTC
Permalink
Found the problem. I am using Liquibase CDI extension in my project and a Liquibase producer.
If I run migrations before, there seems to be a problem with the datasource and injection of EntityManager.

Removing all Liquibase extensions made the project running.
Looks like cdi instance is null in this context. Do you have a sample reproducing it?
Hi,
I have tried to create a small application based on Meecrowave and JPA extension. But when I always try to persist an entity, it fails with a NullPointerException which I cannot really drill down to find the root cause.
First I thought injected EntityManager is null but logging the EntityManager call told me, that it really exists. PersistenceUnitInfoBuilder and DataSource is produced like described on
http://openwebbeans.apache.org/meecrowave/meecrowave-jpa/index.html <http://openwebbeans.apache.org/meecrowave/meecrowave-jpa/index.html>
[...]
Someone can give me a hint what I am doing wrong?
Kind regards,
Björn
Björn Berg
2017-11-22 22:58:20 UTC
Permalink
One addition because my latest post was not right. It is not Liquibase, it is an embedded Id I use in a different class, added to the persistence context.

When I remove the class, everything is fine.
When I add a single @Id annotation, everything is fine.

This is the entity class and its embedded Id:

@Getter
@Setter
@Entity
@Table(name = "PORTFOLIO")
public class Portfolio {
@EmbeddedId
private PortfolioId portfolioId;

@Column(name = "NOMINAL")
private BigDecimal nominal;

@Column(name = "CURRENCY")
private String currency;




}

@Getter
@Setter
@Embeddable
public class PortfolioId {
@Temporal(TemporalType.DATE)
@Column(name = "NAV_DATE", nullable = false)
private Date navDate;

@Column(name = "ISIN", nullable = false, length = 12)
private String isin;

public PortfolioId() {}


}

What’s wrong with it?

Björn
Post by Björn Berg
Found the problem. I am using Liquibase CDI extension in my project and a Liquibase producer.
If I run migrations before, there seems to be a problem with the datasource and injection of EntityManager.
Removing all Liquibase extensions made the project running.
Looks like cdi instance is null in this context. Do you have a sample reproducing it?
Hi,
I have tried to create a small application based on Meecrowave and JPA extension. But when I always try to persist an entity, it fails with a NullPointerException which I cannot really drill down to find the root cause.
First I thought injected EntityManager is null but logging the EntityManager call told me, that it really exists. PersistenceUnitInfoBuilder and DataSource is produced like described on
http://openwebbeans.apache.org/meecrowave/meecrowave-jpa/index.html <http://openwebbeans.apache.org/meecrowave/meecrowave-jpa/index.html>
[...]
Someone can give me a hint what I am doing wrong?
Kind regards,
Björn
Romain Manni-Bucau
2017-11-23 05:32:31 UTC
Permalink
Can depend your jpa provider. Maybe try adding @Vetoed on it or exclude it
from meecrowave option or CDI beans.xml excludes.
Post by Björn Berg
One addition because my latest post was not right. It is not Liquibase, it
is an embedded Id I use in a different class, added to the persistence
context.
When I remove the class, everything is fine.
@Getter
@Setter
@Entity
@Table(name = "PORTFOLIO")
public class Portfolio {
@EmbeddedId
private PortfolioId portfolioId;
@Column(name = "NOMINAL")
private BigDecimal nominal;
@Column(name = "CURRENCY")
private String currency;


}
@Getter
@Setter
@Embeddable
public class PortfolioId {
@Temporal(TemporalType.DATE)
@Column(name = "NAV_DATE", nullable = false)
private Date navDate;
@Column(name = "ISIN", nullable = false, length = 12)
private String isin;
public PortfolioId() {}


}
What’s wrong with it?
Björn
Found the problem. I am using Liquibase CDI extension in my project and a
Liquibase producer.
If I run migrations before, there seems to be a problem with the
datasource and injection of EntityManager.
Removing all Liquibase extensions made the project running.
Looks like cdi instance is null in this context. Do you have a sample reproducing it?
Post by Björn Berg
Hi,
I have tried to create a small application based on Meecrowave and JPA
extension. But when I always try to persist an entity, it fails with a
NullPointerException which I cannot really drill down to find the root
cause.
First I thought injected EntityManager is null but logging the
EntityManager call told me, that it really exists.
PersistenceUnitInfoBuilder and DataSource is produced like described on
http://openwebbeans.apache.org/meecrowave/meecrowave-jpa/index.html
[...]
Someone can give me a hint what I am doing wrong?
Kind regards,
Björn
Björn Berg
2017-11-23 20:04:55 UTC
Permalink
I am indirectly using OpenJpa with meecrowave-jpa component. @Vetoed does not help and there is no beans.xml.
Seems to be a problem with all kinds of EmbeddedId or IdClass.
I have added my sample to GitHub: https://github.com/rollinhand/meecrowave-jpa-sample

What do you mean with "exclude it from meecrowave option“?
Post by Björn Berg
One addition because my latest post was not right. It is not Liquibase, it is an embedded Id I use in a different class, added to the persistence context.
When I remove the class, everything is fine.
@Getter
@Setter
@Entity
@Table(name = "PORTFOLIO")
public class Portfolio {
@EmbeddedId
private PortfolioId portfolioId;
@Column(name = "NOMINAL")
private BigDecimal nominal;
@Column(name = "CURRENCY")
private String currency;


}
@Getter
@Setter
@Embeddable
public class PortfolioId {
@Temporal(TemporalType.DATE)
@Column(name = "NAV_DATE", nullable = false)
private Date navDate;
@Column(name = "ISIN", nullable = false, length = 12)
private String isin;
public PortfolioId() {}


}
What’s wrong with it?
Björn
Post by Björn Berg
Found the problem. I am using Liquibase CDI extension in my project and a Liquibase producer.
If I run migrations before, there seems to be a problem with the datasource and injection of EntityManager.
Removing all Liquibase extensions made the project running.
Looks like cdi instance is null in this context. Do you have a sample reproducing it?
Hi,
I have tried to create a small application based on Meecrowave and JPA extension. But when I always try to persist an entity, it fails with a NullPointerException which I cannot really drill down to find the root cause.
First I thought injected EntityManager is null but logging the EntityManager call told me, that it really exists. PersistenceUnitInfoBuilder and DataSource is produced like described on
http://openwebbeans.apache.org/meecrowave/meecrowave-jpa/index.html <http://openwebbeans.apache.org/meecrowave/meecrowave-jpa/index.html>
[...]
Someone can give me a hint what I am doing wrong?
Kind regards,
Björn
Romain Manni-Bucau
2017-11-23 21:09:20 UTC
Permalink
Hmm

Theses classes are not scanned inti the jpa extension. Can be missing. Want
to try to patch it to test?
Post by Björn Berg
not help and there is no beans.xml.
Seems to be a problem with all kinds of EmbeddedId or IdClass.
I have added my sample to GitHub: https://github.com/
rollinhand/meecrowave-jpa-sample
What do you mean with "exclude it from meecrowave option“?
from meecrowave option or CDI beans.xml excludes.
Post by Björn Berg
One addition because my latest post was not right. It is not Liquibase,
it is an embedded Id I use in a different class, added to the persistence
context.
When I remove the class, everything is fine.
@Getter
@Setter
@Entity
@Table(name = "PORTFOLIO")
public class Portfolio {
@EmbeddedId
private PortfolioId portfolioId;
@Column(name = "NOMINAL")
private BigDecimal nominal;
@Column(name = "CURRENCY")
private String currency;


}
@Getter
@Setter
@Embeddable
public class PortfolioId {
@Temporal(TemporalType.DATE)
@Column(name = "NAV_DATE", nullable = false)
private Date navDate;
@Column(name = "ISIN", nullable = false, length = 12)
private String isin;
public PortfolioId() {}


}
What’s wrong with it?
Björn
Found the problem. I am using Liquibase CDI extension in my project and a
Liquibase producer.
If I run migrations before, there seems to be a problem with the
datasource and injection of EntityManager.
Removing all Liquibase extensions made the project running.
Looks like cdi instance is null in this context. Do you have a sample reproducing it?
Post by Björn Berg
Hi,
I have tried to create a small application based on Meecrowave and JPA
extension. But when I always try to persist an entity, it fails with a
NullPointerException which I cannot really drill down to find the root
cause.
First I thought injected EntityManager is null but logging the
EntityManager call told me, that it really exists.
PersistenceUnitInfoBuilder and DataSource is produced like described on
http://openwebbeans.apache.org/meecrowave/meecrowave-jpa/index.html
[...]
Someone can give me a hint what I am doing wrong?
Kind regards,
Björn
Björn Berg
2017-11-23 21:09:45 UTC
Permalink
So stupid. I had to enhance my entities for usage with OpenJPA.
Only if enhancement tool worked on entities, IdClass and EmbeddedId working properly.
The option openjpa.RuntimeUnenhancedClasses = supported does not work for composite keys.
Post by Björn Berg
Seems to be a problem with all kinds of EmbeddedId or IdClass.
I have added my sample to GitHub: https://github.com/rollinhand/meecrowave-jpa-sample <https://github.com/rollinhand/meecrowave-jpa-sample>
What do you mean with "exclude it from meecrowave option“?
Post by Björn Berg
One addition because my latest post was not right. It is not Liquibase, it is an embedded Id I use in a different class, added to the persistence context.
When I remove the class, everything is fine.
@Getter
@Setter
@Entity
@Table(name = "PORTFOLIO")
public class Portfolio {
@EmbeddedId
private PortfolioId portfolioId;
@Column(name = "NOMINAL")
private BigDecimal nominal;
@Column(name = "CURRENCY")
private String currency;


}
@Getter
@Setter
@Embeddable
public class PortfolioId {
@Temporal(TemporalType.DATE)
@Column(name = "NAV_DATE", nullable = false)
private Date navDate;
@Column(name = "ISIN", nullable = false, length = 12)
private String isin;
public PortfolioId() {}


}
What’s wrong with it?
Björn
Post by Björn Berg
Found the problem. I am using Liquibase CDI extension in my project and a Liquibase producer.
If I run migrations before, there seems to be a problem with the datasource and injection of EntityManager.
Removing all Liquibase extensions made the project running.
Looks like cdi instance is null in this context. Do you have a sample reproducing it?
Hi,
I have tried to create a small application based on Meecrowave and JPA extension. But when I always try to persist an entity, it fails with a NullPointerException which I cannot really drill down to find the root cause.
First I thought injected EntityManager is null but logging the EntityManager call told me, that it really exists. PersistenceUnitInfoBuilder and DataSource is produced like described on
http://openwebbeans.apache.org/meecrowave/meecrowave-jpa/index.html <http://openwebbeans.apache.org/meecrowave/meecrowave-jpa/index.html>
[...]
Someone can give me a hint what I am doing wrong?
Kind regards,
Björn
Romain Manni-Bucau
2017-11-24 05:41:21 UTC
Permalink
Oh right. Same for relationships BTW.
Post by Björn Berg
So stupid. I had to enhance my entities for usage with OpenJPA.
Only if enhancement tool worked on entities, IdClass and EmbeddedId working properly.
The option openjpa.RuntimeUnenhancedClasses = supported does not work for composite keys.
not help and there is no beans.xml.
Seems to be a problem with all kinds of EmbeddedId or IdClass.
I have added my sample to GitHub: https://github.com/
rollinhand/meecrowave-jpa-sample
What do you mean with "exclude it from meecrowave option“?
from meecrowave option or CDI beans.xml excludes.
Post by Björn Berg
One addition because my latest post was not right. It is not Liquibase,
it is an embedded Id I use in a different class, added to the persistence
context.
When I remove the class, everything is fine.
@Getter
@Setter
@Entity
@Table(name = "PORTFOLIO")
public class Portfolio {
@EmbeddedId
private PortfolioId portfolioId;
@Column(name = "NOMINAL")
private BigDecimal nominal;
@Column(name = "CURRENCY")
private String currency;


}
@Getter
@Setter
@Embeddable
public class PortfolioId {
@Temporal(TemporalType.DATE)
@Column(name = "NAV_DATE", nullable = false)
private Date navDate;
@Column(name = "ISIN", nullable = false, length = 12)
private String isin;
public PortfolioId() {}


}
What’s wrong with it?
Björn
Found the problem. I am using Liquibase CDI extension in my project and a
Liquibase producer.
If I run migrations before, there seems to be a problem with the
datasource and injection of EntityManager.
Removing all Liquibase extensions made the project running.
Looks like cdi instance is null in this context. Do you have a sample reproducing it?
Post by Björn Berg
Hi,
I have tried to create a small application based on Meecrowave and JPA
extension. But when I always try to persist an entity, it fails with a
NullPointerException which I cannot really drill down to find the root
cause.
First I thought injected EntityManager is null but logging the
EntityManager call told me, that it really exists.
PersistenceUnitInfoBuilder and DataSource is produced like described on
http://openwebbeans.apache.org/meecrowave/meecrowave-jpa/index.html
[...]
Someone can give me a hint what I am doing wrong?
Kind regards,
Björn
Loading...