0

I have a strange issue after using mvn install in my project.

If I run mvn clean before all, and I start my project inside Eclipse, I have not problem.

After running mvn install (I need this command to generate jar with assembly) and restarting project, I have strange exceptions saving data with hibernate because the transaction is not open.

One of this:

 java.lang.RuntimeException: java.lang.IllegalArgumentException: id to load is required for loading
    at com.econorma.ft2500.util.concurrent.UserTransactionRunnable.run(UserTransactionRunnable.java:20)
    at com.econorma.ft2500.util.concurrent.ContextAwareExectuor$CDIRunnable.run(ContextAwareExectuor.java:67)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:178)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
    Caused by: java.lang.IllegalArgumentException: id to load is required for loading
    at org.hibernate.event.spi.LoadEvent.<init>(LoadEvent.java:109)
    at org.hibernate.event.spi.LoadEvent.<init>(LoadEvent.java:79)
    at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.load(SessionImpl.java:2548)
    at org.hibernate.internal.SessionImpl.get(SessionImpl.java:955)
    at org.hibernate.jpa.spi.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:1110)
    at org.hibernate.jpa.spi.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:1068)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.jboss.weld.bean.proxy.AbstractBeanInstance.invoke(AbstractBeanInstance.java:38)
    at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:100)
    at org.jboss.weld.proxies.EntityManager$827868750$Proxy$_$$_WeldClientProxy.find(Unknown Source)
    at com.econorma.ft2500.MeasureCache$UpdateLatestMeasure.runInTransaction(MeasureCache.java:136)
    at com.econorma.ft2500.util.concurrent.UserTransactionRunnable.run(UserTransactionRunnable.java:16)
    ... 8 more

Here is my beans.xml placed correctly in src/main/resources/META-INF:

 <?xml version="1.0" encoding="UTF-8"?>
  <beans xmlns="http://java.sun.com/xml/ns/javaee"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
<interceptors>
    <class>com.econorma.ft2500.cdi.SynchronizedInterceptor</class>
    <class>org.apache.deltaspike.jpa.impl.transaction.TransactionalInterceptor</class>
</interceptors>

Transactional Class:

public abstract class UserTransactionRunnable implements Runnable{

    protected @Inject EntityManager em; 

    @Override
    public void run() {
        EntityTransaction transaction = em.getTransaction();
        transaction.begin();
        try{
            runInTransaction();
            transaction.commit();
        }catch(Exception e){
            transaction.rollback();
            throw new RuntimeException(e);
        }finally{

        }

    }

    protected abstract void runInTransaction();
}

My consideration is that mvn install command generating TARGET folder lost connection to beans.xml.

Alessandro Mattiuzzi
  • 1,871
  • 1
  • 15
  • 24
  • Could you post your full exception stacktrace? That would be helpful for others to narrow down your problem and did you try debugging it? And make sure your table doesn't have invalid/non-id columns. – Lucky Aug 27 '15 at 08:13
  • In my opinion is not a definition fields problem. Anyway I attached one of the exceptions I got because transaction is not open. – Alessandro Mattiuzzi Aug 27 '15 at 08:24
  • Have you tried lazy loading the entity using [FetchType.Lazy](http://stackoverflow.com/questions/2192242/what-is-lazy-loading-in-hibernate) and make sure you are not passing null id in the `find()` method.[Related Link](http://stackoverflow.com/a/21506213/1793718) – Lucky Aug 27 '15 at 08:41
  • Yes I'm using Lazy annotation. Id is really null in find method, because previous save not working as well. I don't find ResourceLocalTransactionStrategy that might be active. – Alessandro Mattiuzzi Aug 27 '15 at 08:55
  • I don't understand the role of the interceptor - does it open transaction? If you think beans.xml is missing after running mvn install, check the generated artefact, whether it realm contains beans.xml in META-INF folder or for WAR it should be in WEB-INF and not in META-INF – OndroMih Aug 28 '15 at 06:10
  • Could you post your `UserTransactionRunnable`? It seems like you're saying your save doesn't work. Can you show us your save? – John Ament Aug 28 '15 at 11:06
  • This problem happens in Eclipse only after launched MVN CLEAN INSTALL. Transaction is not open. If I clear projects inside Eclipse and relaunch everything is ok. BEANS.XML inside jar is present and – Alessandro Mattiuzzi Aug 28 '15 at 12:58
  • Are you spanning a resource-local transaction over multiple threads? – dieterh May 02 '17 at 13:10

0 Answers0