-
1. Re: How to update foreign key on associated entity?
luxspes Aug 6, 2008 12:01 AM (in response to accountclosed)Have you read about cascading in the core documentation, and how to configure it using annotations?
BTW I think this is a question for the Hibernate Forums, if you have further questions please make them there.
-
2. Re: How to update foreign key on associated entity?
accountclosed Aug 6, 2008 12:31 AM (in response to accountclosed)Have you read about cascading in the core documentation,
Yes I have but it doesn't have anything to do with annotations unfortunately. Also the link you've directed me to points to using sessions. I'm using Seam's injected entity manager which is an entirely different animal.
and how to configure it using annotations?Yes I have. The link you've provided me points to annotations that I'm already in my code. I am using CascadeType.ALL so any and all cascading should be performed. I'm also going by how the hibernate example of one-to-one is given based on this document:
But still with no luck.
BTW I think this is a question for the Hibernate Forums, if you have further questions please make them there.Problem is if I mention Seam in there (the hibernate forum), no one touches it because they all consider the question to be a Seam issue. One forum tells me to go to the other forum, and round and round I go. Also, and like I mentioned earlier, I'm using Seam's injected entity manager which is of type:
org.jboss.seam.persistence.FullTextEntityManagerProxy... so the persistence implementation is very much within the Seam framework. Sorry if I sound terse, but I get the impression that you didn't read the context of my problem.
-
3. Re: How to update foreign key on associated entity?
luxspes Aug 6, 2008 12:38 AM (in response to accountclosed)Maybe you are missing em.flush() or not committing the transaction (what FlusModeType are you using?).
-
4. Re: How to update foreign key on associated entity?
accountclosed Aug 6, 2008 12:54 AM (in response to accountclosed)Francisco,
Thanks for getting back to me so quickly. the flush() method seemed to be the problem. Thank you for your help and your patience, very much appreciated.
:)
-
5. Re: How to update foreign key on associated entity?
accountclosed Aug 6, 2008 1:11 AM (in response to accountclosed)I spoke too soon. I get problems with duplicate id values after updating with a second record (but thanks anyways). I think I'm going to have to re-evaluate whether or not to use Hibernate and Seam since using them cannot produce a simple foreign key relationship. I've tried doing it based on what the hibernate annotations documentation prescribes, what the JPA docs prescribe, and several other sites but no foreign key in the underlying DDL in MySQL.
-
6. Re: How to update foreign key on associated entity?
obfuscator Aug 6, 2008 9:40 AM (in response to accountclosed)I can assure you that it works, and it works for hundreds of entities. I think that updatable causes the problem.
-
7. Re: How to update foreign key on associated entity?
luxspes Aug 6, 2008 6:53 PM (in response to accountclosed)Yes, I agree, what is that updatable = false doing there? IMHO it shouldn't be there.
-
8. Re: How to update foreign key on associated entity?
accountclosed Aug 6, 2008 8:21 PM (in response to accountclosed)I assure you it doesn't ... at least not the way the documentation is suggesting that it does. Also, updatable has no impact.
There is a bug report opened which is called Foreign key name on @OneToOne which is found at the Hibernate JIRA web site.
The description for this bug is:
Foreign key constraint name cannot be changed using @org.hibernate.annotations.ForeignKey on a @OneToOne with foreign key. It doesn't matter which class is annotated with @ForeignKey.The bug was reported 22/Oct/07 and is unresolved. So creating a foreign key for a one-to-one relationship using the ForeignKey annotation has been broken for almost a year. I can't see how this is considered
a minor lost of function
since this seems to be a pretty important piece of functionality.The Hibernate annotations documentation in section 2.4.5. Single Association related annotations, states that:
Foreign key constraints, while generated by Hibernate, have a fairly unreadable name. You can override the constraint name by use @ForeignKey.Which alludes to the generation of foreign keys but shows no examples on how one goes about forcing Hibernate to generate and use these
fairly unreadable
foreign key names. And again, using the Foreign key annotation (mentioned in the above bug report) doesn't work.Incidentally, the above bug report points to an original forum post which actually has a solution. Half way down the page, a fellow going by the name of efriedman offers a solution that uses the GenericGenerator annotation. He sets the strategy to the string value
foreign
. How on Earth is a developer suppose to guess that this would work? This really should be in the documentation - either Seam or Hibernate or better yet, both ... since Hibernate annotations are an integral part of Seam.It doesn't matter how great the framework is, if developers can't figure out how to use it, they won't.