Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with two levels inheritance

 
Paco García
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello to everbody.

This is my first post in this forum, so I hope you to be patient with me.
Thank you for do it.


I'm novice at Hibernate, and I already have a big problem with it.

I'm going to try to explain it as much clear as I can.

I have a big table (ITEMS) which contains all kind of items of my company. This table can't be split into different tables for each kind, so I have to use a table-per-class strategy to manage all kind of objects.

This table contains two big group of items (COMPONENTS AND FINAL PRODUCTS) and each of this big groups is divided into two sub-groups (MANUFACTURED AND PURCHASED).

Components/final products items are discriminated by a column (cpgp). All components have value 5 in this field and all final products have 1 in it.

And all purchased items have value 1 in field kitm, while all manufactured items have value 2.

So I have four kinds of items:
Final Product/Purchased : cpgp=1/kitm=1
Final Product/Manufactured : cpgp=1/kitm=2
Component/Purchased: t$cpgp=5/kitm=2
Component/Manufactured : cpgp=5/kitm=2

(If someone knows Baan database, he knows what I'm explaning)


My first approach was to create a discriminator with two fields (cpgp and kitm), but I've been "googling" for a while and I think that this is not possible.

Then, I have created a tree inheritance. Component class and FinalProduct inherits from Item, and ManufacturedComponent Class and PurchasedComponent inherits from Component, while ManufacturedFinalProduct and PurchasedFinalProduct inherits from FinalProduct

Item has a discriminator column (cpgp) and Component has a discriminator value (5).
ManufacturedComponent, purchasedComponent, ManufacturedFinalProduct and PurchasedFinalProduct have a filter in the t$kitm field and they don't have a discriminator value, so hibernate only load those records I need.

But when I try to load any record belonging to any of these four classes, I always get a null record. Looking into the log I've seen that the query parsed to oracle has the condition "cpgp='ManufacturedComponent'" instead of "cpgp='5'".

If I put a discriminator value (5) in Component class and in ManufacturedComponent, or I put discriminator value (5) in ManufacturedComponent and in PurchasedComponent, I get an Exception (Initial Session Factory creation failes.org.hibernate.MappingException: Error parsing discriminator value)


Can anyone help me to solve this issue?


Thansk in advance.








 
K. Tsang
Bartender
Posts: 3585
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

Why don't you try setting the DiscrimatorType to INTEGER in the Item class? Then in your concrete classes set value=5 or whatever.

 
Paco García
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your reply.

The discriminator is a String with two values " 500" and " 1", but I've post 5 in order to make a simpler post.

 
Paco García
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now I have created a new virtual column in Oracle as the concatenation of the two columns (cpgp and kitm), then I can do a simple discriminator from this new column.
But, not when I create a new object in any class (i.e. ManufacturedComponent) I get an exception because Hibernate tries to insert a value in this new virtual column.



Is there any method to tell Hibernate not to insert a value into the discriminator column?

i.e.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic