ejb@glassfish.java.net

Re: Transactions taking too long in _at_OneToMany relation

From: Michal Kováč <mkakacm_at_gmail.com>
Date: Sat, 12 Dec 2009 03:40:07 +0100

Thank you for response, Jose.
I've just tried it, but I'm experiencing exactly the same behavior.

On Sat, Dec 12, 2009 at 12:32 AM, Jose Alvarez de Lara <
dakhla.0563_at_hotmail.com> wrote:

> Hi Michal,
>
> This is your code snippet,
>
>
> @Entity public class Contact implements Serializable {
> private static final long serialVersionUID = 1L;
> @Id
> @GeneratedValue(strategy = GenerationType.AUTO)
> private Long id;
> private String name;
> private String surname;
> @OneToMany(cascade = CascadeType.REMOVE, mappedBy = "contact")
> private Collection<PhoneNumber> phoneNumbers = new ArrayList<PhoneNumber>();
>
> take it from
>
> http://stackoverflow.com/questions/1858153/ejb-and-jpa-and-onetomany-transaction-too-long
>
> I should make the following,
>
> @OneToMany(cascade = CascadeType.REMOVE, mappedBy = "contact",
>
> targetEntity=PhoneNumber.
> *class*,
>
> fetch=FetchType.
> *EAGER*)
>
>
>
> Try this and let me know if it does work better.
>
>
>
> Regards,
>
> Jose
>
>
> *From:* Michal Kováč <mkakacm_at_gmail.com>
> *Sent:* Friday, December 11, 2009 12:34 AM
> *To:* ejb_at_glassfish.dev.java.net
> *Subject:* Transactions taking too long in @OneToMany relation
>
> Hello,
> I'm trying to do simple Java EE application, just to get a hold of EJB3 and
> I'm stuck for quite a few days. I've posted my problem on stackoverflow:
>
>
> http://stackoverflow.com/questions/1858153/ejb-and-jpa-and-onetomany-transaction-too-long
>
> One behavior I haven't mentioned in that post is this: when I create and
> persist a Contact object and want to add a PhoneNumber object to it, it
> takes long time (which varies) to take effect. When I try to remove that
> Contact object before the PhoneNumber is returned (it is in DB, it just
> can't be returned via EntityManager's find method immediately), I get
> transaction.RollbackException (DELETE on table 'CONTACT' caused a violation
> of foreign key constraint 'PHNENUMBERCNTACTID' for key (2401). The
> statement has been rolled back) - even thought removing works well on the
> same object a little later, when PhoneNumber object is found.
>
> I tried to set fetch method to eager, that didn't work. When I try to run
> em.refresh right after I added the phoneNumber with em.create, it's saying
> entity is not managed.
>
> If you need additional information or source code, please let me know.
>
> Thank you
>
>