[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [eclipselink-users] Fwd: null value ONCASCADE=PERSIST and XA Resources
|
Hello John,
I didn't notice that you are not setting the Item's invoice. Generally,
a 1:M when using a foreign key requires that the target have a M:1 back,
and it is this M:1 back that defines and controls the foreign key
value. Since the INVOICE_ID is being set to null, you probably have
this mapped correctly and instead are just leaving the relationship as
null. To get it set, when you add an item to invoice's list of Items,
you also need to set the back pointer. JPA does not maintain
bidirectional relationships for you.
Best Regards,
Chris
christopher delahunt wrote:
1) How have you set the invoice's primary key, and how are the
ProductItem <--> Invoice mappings defined?
2) I can't say too much, it looks like a container setup issue. The
exception is stating you cant use two different transactional
resources inside a single transaction; Two JTA datasources cannot be
involved in 1 transaction without XA, which is what you seem to be
attempting to do with your current configuration and use of two
persistence contexts. If you don't want to use XA, make one of the
persistence context not use a JTA datasource and manage the
transactions through the application directly. Ie make one resource
local and let the other take part in the JTA transaction. Of course,
this will require transaction management on the resource local
persistence context, so you may just want to use XA instead.
Best Regards,
Chris
John Arevalo wrote:
Hi list, I'm facing 2 problems with JPA
1) I have an OneToMany relationship between Invoice and ProductItem,
when i try to create a new invoice:
Invoice invoice = new Invoice();
ArrayList<ProductItem> items = new ArrayList<ProductItem>();
for(/*any iteration*/) {
item = new ProductItem();
item.setQuantity(myQuantity);
items.add(item);
}
invoice.setProductItems(items);
invoiceFacade.create(invoice);
throws an SQLException because native query is: INSERT INTO
PRODUCT_ITEM(QUANTITY, INVOICE_ID) VALUES(3, null);
should i persist invoice before add items to it? in that piece of code
i can manage transaction in create(Invoice) method...persisting
invoice object first, I have to manage Transaction outside of EJB
method, or create another one.
2) another Exception is thrown in several "INSERT" actions. I have
Oracle PersistenceContext and DB2 PersistenceContext in EJB module,
message is:
Local transaction already has 1non-XA Resource: cannot add more
resources.
reading this post [1], looks like i need XADatasource when i use
different pool resources. Really i don't have to persist objects from
DB2, so i don't need distribuited transactions, can i disable XA?
[1]http://www.theserverside.com/discussions/thread.tss?thread_id=21385#95346
Thanks for your replies,
Best regards.
--
John Arévalo
GNU/Linux User #443701
http://counter.li.org/
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users