You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@deltaspike.apache.org by Pa...@b-m.pl on 2016/05/10 15:40:27 UTC

having problem with remove entity in data module

Hi Team,

Almost I succeeded to use data module except 'remove' method of my 
repository. Having simple test:

        @org.junit.Test
        public void test2(){
                Something something = new Something();
                something.setName( "Name" );
                somethingDao.save( something );
                log.info( something.getId() );
                somethingDao.remove( somethingDao.findBy( 
something.getId() ) );
        }

fails with 

test2(test.DeltaspikeTest)  Time elapsed: 0.016 sec  <<< ERROR!
org.apache.deltaspike.data.api.QueryInvocationException: Failed calling 
Repository: 
[Repository=pack1.SomethingDao,entity=pack1.Something,method=remove,exception=class 
org.apache.deltaspike.data.api.QueryInvocationException,message=Failed 
calling Repository: 
[Repository=pack1.SomethingDao,entity=pack1.Something,method=remove,exception=class 
org.apache.deltaspike.data.api.QueryInvocationException,message=Failed 
calling Repository: 
[Repository=pack1.SomethingDao,entity=pack1.Something,method=remove,exception=class 
java.lang.reflect.InvocationTargetException,message=null
        at test.DeltaspikeTest.test2(DeltaspikeTest.java:36)
Caused by: org.apache.deltaspike.data.api.QueryInvocationException: Failed 
calling Repository: 
[Repository=pack1.SomethingDao,entity=pack1.Something,method=remove,exception=class 
org.apache.deltaspike.data.api.QueryInvocationException,message=Failed 
calling Repository: 
[Repository=pack1.SomethingDao,entity=pack1.Something,method=remove,exception=class 
java.lang.reflect.InvocationTargetException,message=null
        at test.DeltaspikeTest.test2(DeltaspikeTest.java:36)
Caused by: org.apache.deltaspike.data.api.QueryInvocationException: Failed 
calling Repository: 
[Repository=pack1.SomethingDao,entity=pack1.Something,method=remove,exception=class 
java.lang.reflect.InvocationTargetException,message=null
        at test.DeltaspikeTest.test2(DeltaspikeTest.java:36)
Caused by: java.lang.reflect.InvocationTargetException
        at test.DeltaspikeTest.test2(DeltaspikeTest.java:36)
Caused by: java.lang.IllegalArgumentException: Entity must be managed to 
call remove: Name, try merging the detached and try the remove again.
        at test.DeltaspikeTest.test2(DeltaspikeTest.java:36)


For me it should obviously work. To regenerate the proble I made a GitHub 
project : https://github.com/p4w3l/deltaspikeTest

Simple call: mvn

and you will see

best regards
Paweł

ODP: Re: having problem with remove entity in data module

Posted by Pa...@b-m.pl.
Hi John,

Tried that and EntityManagerAware or rather EntityManagerDelegate with 
'find' and 'getReference' and 'merge'

I really did all homeworks. They ALL doesn't work  !!!

Please try with my test project with yours modifications and show me just 
one new test that works with remove: 

> git clone https://github.com/p4w3l/deltaspikeTest.git
> cd deltaspikeTest
> mvn

Please! Thanks in advance!

best regards
Paweł



Od:     "John D. Ament" <jo...@apache.org>
Do:     users@deltaspike.apache.org
Data:   2016-05-10 19:55
Temat:  Re: having problem with remove entity in data module



That's normal JPA behavior.  You have to have a managed entity to do this.
Simple way is to do something like

Something something = new Something();
something.setName( "Name" );
Something saved = somethingDao.save( something );
somethingDao.remove( saved );

Otherwise you should extend from EntityManagerAware and use the find 
method
there.

John

On Tue, May 10, 2016 at 11:40 AM <Pa...@b-m.pl> wrote:

> Hi Team,
>
> Almost I succeeded to use data module except 'remove' method of my
> repository. Having simple test:
>
>         @org.junit.Test
>         public void test2(){
>                 Something something = new Something();
>                 something.setName( "Name" );
>                 somethingDao.save( something );
>                 log.info( something.getId() );
>                 somethingDao.remove( somethingDao.findBy(
> something.getId() ) );
>         }
>
> fails with
>
> test2(test.DeltaspikeTest)  Time elapsed: 0.016 sec  <<< ERROR!
> org.apache.deltaspike.data.api.QueryInvocationException: Failed calling
> Repository:
>
> 
[Repository=pack1.SomethingDao,entity=pack1.Something,method=remove,exception=class
> org.apache.deltaspike.data.api.QueryInvocationException,message=Failed
> calling Repository:
>
> 
[Repository=pack1.SomethingDao,entity=pack1.Something,method=remove,exception=class
> org.apache.deltaspike.data.api.QueryInvocationException,message=Failed
> calling Repository:
>
> 
[Repository=pack1.SomethingDao,entity=pack1.Something,method=remove,exception=class
> java.lang.reflect.InvocationTargetException,message=null
>         at test.DeltaspikeTest.test2(DeltaspikeTest.java:36)
> Caused by: org.apache.deltaspike.data.api.QueryInvocationException: 
Failed
> calling Repository:
>
> 
[Repository=pack1.SomethingDao,entity=pack1.Something,method=remove,exception=class
> org.apache.deltaspike.data.api.QueryInvocationException,message=Failed
> calling Repository:
>
> 
[Repository=pack1.SomethingDao,entity=pack1.Something,method=remove,exception=class
> java.lang.reflect.InvocationTargetException,message=null
>         at test.DeltaspikeTest.test2(DeltaspikeTest.java:36)
> Caused by: org.apache.deltaspike.data.api.QueryInvocationException: 
Failed
> calling Repository:
>
> 
[Repository=pack1.SomethingDao,entity=pack1.Something,method=remove,exception=class
> java.lang.reflect.InvocationTargetException,message=null
>         at test.DeltaspikeTest.test2(DeltaspikeTest.java:36)
> Caused by: java.lang.reflect.InvocationTargetException
>         at test.DeltaspikeTest.test2(DeltaspikeTest.java:36)
> Caused by: java.lang.IllegalArgumentException: Entity must be managed to
> call remove: Name, try merging the detached and try the remove again.
>         at test.DeltaspikeTest.test2(DeltaspikeTest.java:36)
>
>
> For me it should obviously work. To regenerate the proble I made a 
GitHub
> project : https://github.com/p4w3l/deltaspikeTest
>
> Simple call: mvn
>
> and you will see
>
> best regards
> Paweł


Re: having problem with remove entity in data module

Posted by "John D. Ament" <jo...@apache.org>.
That's normal JPA behavior.  You have to have a managed entity to do this.
Simple way is to do something like

Something something = new Something();
something.setName( "Name" );
Something saved = somethingDao.save( something );
somethingDao.remove( saved );

Otherwise you should extend from EntityManagerAware and use the find method
there.

John

On Tue, May 10, 2016 at 11:40 AM <Pa...@b-m.pl> wrote:

> Hi Team,
>
> Almost I succeeded to use data module except 'remove' method of my
> repository. Having simple test:
>
>         @org.junit.Test
>         public void test2(){
>                 Something something = new Something();
>                 something.setName( "Name" );
>                 somethingDao.save( something );
>                 log.info( something.getId() );
>                 somethingDao.remove( somethingDao.findBy(
> something.getId() ) );
>         }
>
> fails with
>
> test2(test.DeltaspikeTest)  Time elapsed: 0.016 sec  <<< ERROR!
> org.apache.deltaspike.data.api.QueryInvocationException: Failed calling
> Repository:
>
> [Repository=pack1.SomethingDao,entity=pack1.Something,method=remove,exception=class
> org.apache.deltaspike.data.api.QueryInvocationException,message=Failed
> calling Repository:
>
> [Repository=pack1.SomethingDao,entity=pack1.Something,method=remove,exception=class
> org.apache.deltaspike.data.api.QueryInvocationException,message=Failed
> calling Repository:
>
> [Repository=pack1.SomethingDao,entity=pack1.Something,method=remove,exception=class
> java.lang.reflect.InvocationTargetException,message=null
>         at test.DeltaspikeTest.test2(DeltaspikeTest.java:36)
> Caused by: org.apache.deltaspike.data.api.QueryInvocationException: Failed
> calling Repository:
>
> [Repository=pack1.SomethingDao,entity=pack1.Something,method=remove,exception=class
> org.apache.deltaspike.data.api.QueryInvocationException,message=Failed
> calling Repository:
>
> [Repository=pack1.SomethingDao,entity=pack1.Something,method=remove,exception=class
> java.lang.reflect.InvocationTargetException,message=null
>         at test.DeltaspikeTest.test2(DeltaspikeTest.java:36)
> Caused by: org.apache.deltaspike.data.api.QueryInvocationException: Failed
> calling Repository:
>
> [Repository=pack1.SomethingDao,entity=pack1.Something,method=remove,exception=class
> java.lang.reflect.InvocationTargetException,message=null
>         at test.DeltaspikeTest.test2(DeltaspikeTest.java:36)
> Caused by: java.lang.reflect.InvocationTargetException
>         at test.DeltaspikeTest.test2(DeltaspikeTest.java:36)
> Caused by: java.lang.IllegalArgumentException: Entity must be managed to
> call remove: Name, try merging the detached and try the remove again.
>         at test.DeltaspikeTest.test2(DeltaspikeTest.java:36)
>
>
> For me it should obviously work. To regenerate the proble I made a GitHub
> project : https://github.com/p4w3l/deltaspikeTest
>
> Simple call: mvn
>
> and you will see
>
> best regards
> Paweł

ODP: Re: having problem with remove entity in data module

Posted by Pa...@b-m.pl.
Wojtek,

you made my day. Dziękuję!

Paweł



Od:     Wojciech Żaboklicki <za...@gmail.com>
Do:     users@deltaspike.apache.org
Data:   2016-05-10 21:20
Temat:  Re: having problem with remove entity in data module



Hi Pawel,
Annotating EntityManagerProducer.create() with @RequestScoped will solve 
your problem.

Kind regards,
Wojtek


> Wiadomość napisana przez Pawel.Maczka@b-m.pl w dniu 10.05.2016, o godz. 
17:40:
> 
> Hi Team,
> 
> Almost I succeeded to use data module except 'remove' method of my 
> repository. Having simple test:
> 
>        @org.junit.Test
>        public void test2(){
>                Something something = new Something();
>                something.setName( "Name" );
>                somethingDao.save( something );
>                log.info( something.getId() );
>                somethingDao.remove( somethingDao.findBy( 
> something.getId() ) );
>        }
> 
> fails with 
> 
> test2(test.DeltaspikeTest)  Time elapsed: 0.016 sec  <<< ERROR!
> org.apache.deltaspike.data.api.QueryInvocationException: Failed calling 
> Repository: 
> 
[Repository=pack1.SomethingDao,entity=pack1.Something,method=remove,exception=class 

> org.apache.deltaspike.data.api.QueryInvocationException,message=Failed 
> calling Repository: 
> 
[Repository=pack1.SomethingDao,entity=pack1.Something,method=remove,exception=class 

> org.apache.deltaspike.data.api.QueryInvocationException,message=Failed 
> calling Repository: 
> 
[Repository=pack1.SomethingDao,entity=pack1.Something,method=remove,exception=class 

> java.lang.reflect.InvocationTargetException,message=null
>        at test.DeltaspikeTest.test2(DeltaspikeTest.java:36)
> Caused by: org.apache.deltaspike.data.api.QueryInvocationException: 
Failed 
> calling Repository: 
> 
[Repository=pack1.SomethingDao,entity=pack1.Something,method=remove,exception=class 

> org.apache.deltaspike.data.api.QueryInvocationException,message=Failed 
> calling Repository: 
> 
[Repository=pack1.SomethingDao,entity=pack1.Something,method=remove,exception=class 

> java.lang.reflect.InvocationTargetException,message=null
>        at test.DeltaspikeTest.test2(DeltaspikeTest.java:36)
> Caused by: org.apache.deltaspike.data.api.QueryInvocationException: 
Failed 
> calling Repository: 
> 
[Repository=pack1.SomethingDao,entity=pack1.Something,method=remove,exception=class 

> java.lang.reflect.InvocationTargetException,message=null
>        at test.DeltaspikeTest.test2(DeltaspikeTest.java:36)
> Caused by: java.lang.reflect.InvocationTargetException
>        at test.DeltaspikeTest.test2(DeltaspikeTest.java:36)
> Caused by: java.lang.IllegalArgumentException: Entity must be managed to 

> call remove: Name, try merging the detached and try the remove again.
>        at test.DeltaspikeTest.test2(DeltaspikeTest.java:36)
> 
> 
> For me it should obviously work. To regenerate the proble I made a 
GitHub 
> project : https://github.com/p4w3l/deltaspikeTest
> 
> Simple call: mvn
> 
> and you will see
> 
> best regards
> Paweł



Re: having problem with remove entity in data module

Posted by Wojciech Żaboklicki <za...@gmail.com>.
Hi Pawel,
Annotating EntityManagerProducer.create() with @RequestScoped will solve your problem.

Kind regards,
Wojtek


> Wiadomość napisana przez Pawel.Maczka@b-m.pl w dniu 10.05.2016, o godz. 17:40:
> 
> Hi Team,
> 
> Almost I succeeded to use data module except 'remove' method of my 
> repository. Having simple test:
> 
>        @org.junit.Test
>        public void test2(){
>                Something something = new Something();
>                something.setName( "Name" );
>                somethingDao.save( something );
>                log.info( something.getId() );
>                somethingDao.remove( somethingDao.findBy( 
> something.getId() ) );
>        }
> 
> fails with 
> 
> test2(test.DeltaspikeTest)  Time elapsed: 0.016 sec  <<< ERROR!
> org.apache.deltaspike.data.api.QueryInvocationException: Failed calling 
> Repository: 
> [Repository=pack1.SomethingDao,entity=pack1.Something,method=remove,exception=class 
> org.apache.deltaspike.data.api.QueryInvocationException,message=Failed 
> calling Repository: 
> [Repository=pack1.SomethingDao,entity=pack1.Something,method=remove,exception=class 
> org.apache.deltaspike.data.api.QueryInvocationException,message=Failed 
> calling Repository: 
> [Repository=pack1.SomethingDao,entity=pack1.Something,method=remove,exception=class 
> java.lang.reflect.InvocationTargetException,message=null
>        at test.DeltaspikeTest.test2(DeltaspikeTest.java:36)
> Caused by: org.apache.deltaspike.data.api.QueryInvocationException: Failed 
> calling Repository: 
> [Repository=pack1.SomethingDao,entity=pack1.Something,method=remove,exception=class 
> org.apache.deltaspike.data.api.QueryInvocationException,message=Failed 
> calling Repository: 
> [Repository=pack1.SomethingDao,entity=pack1.Something,method=remove,exception=class 
> java.lang.reflect.InvocationTargetException,message=null
>        at test.DeltaspikeTest.test2(DeltaspikeTest.java:36)
> Caused by: org.apache.deltaspike.data.api.QueryInvocationException: Failed 
> calling Repository: 
> [Repository=pack1.SomethingDao,entity=pack1.Something,method=remove,exception=class 
> java.lang.reflect.InvocationTargetException,message=null
>        at test.DeltaspikeTest.test2(DeltaspikeTest.java:36)
> Caused by: java.lang.reflect.InvocationTargetException
>        at test.DeltaspikeTest.test2(DeltaspikeTest.java:36)
> Caused by: java.lang.IllegalArgumentException: Entity must be managed to 
> call remove: Name, try merging the detached and try the remove again.
>        at test.DeltaspikeTest.test2(DeltaspikeTest.java:36)
> 
> 
> For me it should obviously work. To regenerate the proble I made a GitHub 
> project : https://github.com/p4w3l/deltaspikeTest
> 
> Simple call: mvn
> 
> and you will see
> 
> best regards
> Paweł