Forums Register Login

OneToOne persisting two objects in a single transaction

+Pie Number of slices to send: Send
On a facade bean I am trying to persist two objects relationed between eachother as shown belowe


In a facade bean I try to persist them in a single transaction, I'd like to have suggestions on my approach. Is there a better way to do it?


Thanks in advance for your suggestions
[ April 18, 2007: Message edited by: Alessandro Ilardo ]
+Pie Number of slices to send: Send
How about



The cascade option of All in the User mapping should automatically insert the UserRole too when persisting the User, that is what Cascade options are all about.

Mark
+Pie Number of slices to send: Send
"On a facade bean"

Why that just flew right by me the first time I read your post.

Wouldn't you want that kind of method in a DAO object? And not tie EJBs or your facade bean to JPA?

Mark
+Pie Number of slices to send: Send
thanks for your reply Mark,
As the user must have one relation with a row in the USR_ROLE, I created a constructore like:

from the client I run


and the EJB

em.persist(user);
and it partially works.

But I'm getting different values from the Primary Keys. I expected to find the same key in both records.

About the DAO.
I used that pattern when I had to write SQL querys, since I've started with EJB3 I'm using a stateless bean to access entity's.
Wrong approach?
Thanks again.
+Pie Number of slices to send: Send
Each table has their own primary key, they wouldn't necessarily have the same ID, you can map so that the two records share the same PK, but I don't remember of the top of my head the mapping to do that.

I still like the model of seperating EJB business logic from Data Access logic. I also still like the idea of even not putting code directly in Beans, but other POJOs, but there is also a way to do that with having your Bean extend the POJO. But having the business logic in the Bean isn't wrong anymore. Since that POJO with the EJB annotations can still work outside the container.

Mark
Put the moon back where you found it! We need it for tides and poetry and stuff. Like this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1269 times.
Similar Threads
Hibernate InheritanceType.SINGLE_TABLE with different eager OneToOne relations
how to update OneToMany
EJB 3.0 design question
non-standard join in ManyToOne
[hibernate] OneToOne add a new child :o(
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 06:31:44.