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.
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.
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
subject: OneToOne persisting two objects in a single transaction