-
1. Re: Editing and Deleting Entity
leonell Jun 25, 2005 8:08 AM (in response to murtuza52)Hello,
at first your client must load instance of Order by your findByKey() method. Now you have detached Order instance with collection of LineItems (assume Eager loading). Now you change something in LineItems collection, for example product name. Next call update() method of your session bean but with your detached local client Order as parameter.
Called Session bean method:public void update(Order orderFromClient) { if (orderFromClient != null) { manager.merge(orderFromClient); } }
Now it works fine.
You can of course rewrite code to using Order instantiated in session bean and write SB method for change specified items .
With delete is some problem because when you remove item from Collection on detached object then merge() does not remove any item from database.
I dont know why for now.
Leonell -
2. Re: Editing and Deleting Entity
murtuza52 Jun 25, 2005 9:11 AM (in response to murtuza52)Is there any other way we can remove the appropriate LineItem from the Database
-
3. Re: Editing and Deleting Entity
leonell Jun 25, 2005 10:50 AM (in response to murtuza52)I hope the version with merge() is correct. When I can by this way add and change item I must also these items remove, isnt it? :-)
I tested also following way (method of SB):@TransactionAttribute(TransactionAttributeType.REQUIRED) public void removeItem(int orderId, String product) { Query q = manager.createQuery("from LineItem o where o.order.id=:orderId and o.product like :product"); q.setParameter("orderId", orderId ); q.setParameter("product", product ); java.util.Collection<LineItem> c = q.getResultList(); for (LineItem li: c) { manager.remove(li); } }
There is as result exception about resave, I dont remember exactly.
I will wait after some time to resolve it...
L. -
4. Re: Editing and Deleting Entity
murtuza52 Jun 26, 2005 2:55 AM (in response to murtuza52)This is very inefficient way of managing your entities with relations as introduces extra layer of complexity in the code. Anyways, the persistence specification section 2.1.7 says following:
"The container handles the object-relational mapping of the relationships, including their loading and storing to the database as specified in the metadata of the bean class, and the referential integrity of the relationships as specified in the database (e.g., by foreign key constraints)."
With this i suppose the current limitation is only temporary untill someone fixes it.
Let me try your approach and will post my results later. -
5. Re: Editing and Deleting Entity
leonell Jun 26, 2005 4:32 AM (in response to murtuza52)"murtuza52" wrote:
This is very inefficient way of managing your entities with relations as introduces extra layer of complexity in the code.
Yes, but you requested some workaround ;-)"murtuza52" wrote:
With this i suppose the current limitation is only temporary untill someone fixes it.
See new topic: Problem with removing item from collection in detached object
I sent example - I hope someone from Jboss Team will answer our question.
Leonell -
6. Re: Editing and Deleting Entity
manica Jun 26, 2005 7:38 PM (in response to murtuza52)I haven't had time to try it yet, but it appears that the new OnDelete annotation will accomplish this.
Darin -
7. Re: Editing and Deleting Entity
murtuza52 Jun 27, 2005 1:29 AM (in response to murtuza52)Hello Manica
I could not find OnDelete annotation in the EJB Specification. Can you point me to right resources so i can try it out.
Murtuza -
8. Re: Editing and Deleting Entity
epbernard Jun 27, 2005 7:32 PM (in response to murtuza52)Partly answered in a previous thread about the orphan delete cascading.
@OnDelete is an hiberate specific annotation.