June 09, 2005

Hibernate one–to–one problems :(

So I have an object Content which has a ContentFetcher (strategy).

Ideally I would like to implement ContentFetcher as a dependant object of Content, but I can't for the following reasons:

– a Content's contentFetcher can change

– dependent objects cannot be polymorphic in hibernate

So I map it as a one-to-one (Content to ContentFetcher) with the primary key of ContentFetcher being the same as the primary key of Content.

Unfortunately when I try and assign a new ContentFetcher, Hibernate explodes because there are two instances of ContentFetcher with the same id, the old one and the new one. There seems to be no way to indicate to Hibernate (without explictly calling session.delete which I haven't tried) to ignore the old content.

In the end I mapped it as a many-to-one with a foreign key in Content :(

Oh well.

- One comment Not publicly viewable

  1. thogau

    I am running into the same problem…
    Did you find a better solution than the many-to-one trick?
    If I do, I'll add a new comment

    18 Nov 2005, 11:40

Add a comment

You are not allowed to comment on this entry as it has restricted commenting permissions.

June 2005

Mo Tu We Th Fr Sa Su
May |  Today  | Jul
      1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30         

Search this blog



Most recent comments

  • Interesting… While I'm not completely convinced in such microbenchmarks, I'm pretty sure that 1ms … by Alexander Snaps on this entry
  • Hello. I bought the book yesterday. I was trying to find the source code for chapter 11 and chapter … by Suleman on this entry
  • http://woosight.net/account/login?username=demo by live mashup demo on this entry
  • Thanks mate ….. This blog was really helpful. by Maaz Hurzuk on this entry
  • Ty. Not directly helpful for my problem, but pointed me in the right direction. You will also get th… by Mike E. on this entry

Blog archive

Not signed in
Sign in

Powered by BlogBuilder