• 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
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

case: id autoincrement for hibernate classes with Inheritance

 
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys

i have a dilemma and doubt about this

i have a superclass call for instance HeaderWarehouse (sorry for my grammar)
and 2 subclasses (Inheritance) RetireWarehouse InsertWarehouse

this is for the control of products in a "Warehouse"
of course each RetireWarehouse-InsertWarehouse has their relations
to RetireDetailsWarehouse InsertDetailsWarehouse

well the superclass can has this fields or variables


and each subclass has a unique Set type variable for
RetireDetailsWarehouse InsertDetailsWarehouse

the problem is this , the id must be autoincrement
so i use xdoclet for hibernate and done

when i create a new instance of the subclasses and they are inserted by hibernate
it create the autoincrement id but for the 2 types

so if i create
for instance 4 new objects for
RetireWarehouse
the id generated should be 1,2,3,4
and thats right

but if i try to create an object for InsertWarehouse i recieve the next number
5

so the question and i need your experience,
how i can have the id autoincrement for each subclass???
that means

4 new objects for
RetireWarehouse
the id generated should be 1,2,3,4

and instead for InsertWarehouse it should recieve the 1

the obvious and wrong solution could be kill the Inheritance and repeat the same variables for each
ex-subclasses, but i dont want lose the Inheritance

i hope you can see my point

thanks for advanced
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Without seeing your mappings or table structures I'll have to make some assumptions...

It sounds like your using the table-per-class hierarchy strategy (you have one table for all HeaderWarehouses). The closest you can come to having separate IDs for each subclass would be to change to the table-per-subclass strategy.

Something like...


This will give you one 'count' for all instance of HeaderWarehouse and separate counts of both InsertWarehouse and RetireWarehouse. Might not be exactly what you're looking for, but it's the best I can think of.
 
Manuel Jordan
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi David

thanks for the reply

well i used to work with Table per Class Hierarchy which work with tag <subclass
and now i tried with Table per subclass which work with tag <joined-subclass

sadly with the same results , the unique and obvious difference is the creation of the tables with the fields in a independence way (has other behaviour),

maybe a composite key can be the solution

regards
 
reply
    Bookmark Topic Watch Topic
  • New Topic