Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Object Relational Mapping
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Object Relational Mapping
Problems with transitive/cascading persistence
Julien Martin
Ranch Hand
Posts: 384
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hello,
I have an entity Poll that can contain multiple entities PossibleAnswer. They are mapped by two tables, one with a pk (Poll) the other with a pk and a fk (PossibleAnswer). It is a bidirectional relationship.
Here is the relevant snippet from PossibleAnswer:
[code] @ManyToOne(cascade=CascadeType.ALL)
@JoinColumn(name="idPoll")
private Poll poll;[code]
Here is the relevant snippet from Poll
[code]@OneToMany(mappedBy="poll")
private Collection<PossibleAnswer> possibleAnswers = new ArrayList<PossibleAnswer>();[code]
I then set the Poll on each possible answer
[code]possibleAnswer1.setPoll(poll)[code]
I then add the possible Answers to the collection.
[code]possibleAnswers.add(possibleAnswer1)[code]
I then set the collection to the Poll as follows:
[code]poll.setPossibleAnswers(possibleAnswers)[code]
and finally I persist the poll.
Only the poll entity gets persisted and therefore the transitive persistence does not work.
I use hibernate as jpa provider.
Can anyone please help?
Julien.
[ November 19, 2007: Message edited by: Julien Martin ]
Mark Spritzler
ranger
Posts: 17347
11
I like...
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Yes you only set the cascade option for one of the directions, not the other. So set the OneToMany mapping to have a cascade option to save it.
Mark
Perfect World Programming, LLC
-
iOS Apps
How to Ask Questions the Smart Way FAQ
Julien Martin
Ranch Hand
Posts: 384
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
thanks Mark!
Consider Paul's
rocket mass heater
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Mysql auto generated PK used for another table and JPA
JBoss CMP read ahead cache problem
Cast Entity association collection to implementation type
Container Error in FindBy methods in JBoss
CMP beans not entering data in database
More...