-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: How to persist a list?
PostPosted: Tue Dec 06, 2011 7:21 am 
Newbie

Joined: Tue Nov 29, 2011 12:42 am
Posts: 3
Hi

1. I have created a list as follows:
ArrayList<Menu> tempList = new ArrayList<Menu>();//Menu is an entity
2. Populating this list with a few 'Menu' objects.
3. then doing:
entityManager.persist(tempList);
At this point I get following exception:
java.lang.IllegalArgumentException: Unknown entity: java.util.ArrayList
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:223)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:240)
at $Proxy26.persist(Unknown Source)

Please guide what I might be missing.
Thanks!


Top
 Profile  
 
 Post subject: Re: How to persist a list?
PostPosted: Tue Dec 06, 2011 2:46 pm 
Newbie

Joined: Mon Jun 21, 2010 9:03 am
Posts: 7
Hi!

I think it is not possible to persist a list, because list not an entity.
Just iterate over the result list and call persist on every entity.
Code:
for(Menu menu : menus)
{
    entityManager.perist(menu);
}


Best regards.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.