-
1. Re: Help With Inheritance
rread Jun 20, 2011 11:40 AM (in response to rread)no one has any ideas?
-
2. Re: Help With Inheritance
nbelaevski Jun 20, 2011 1:50 PM (in response to rread)Hi Felix,
This forum is dedicated to RichFaces, so I'm going to move this thread to Persistence forum.
-
3. Re: Help With Inheritance
wdfink Jun 21, 2011 3:58 AM (in response to rread)I'm not sure about your problem
If you implement like this and create two persons (one as supplier and one as customer) they will be different, but if I understand right you want to achieve that a single person is a customer AND a supplier right?
-
4. Re: Help With Inheritance
rread Jun 21, 2011 10:05 AM (in response to wdfink)yes
TPerson
id name
1 xxxxxxxx
TCostumer
id birthdate
1 xx/xx/xxxx
TSupplier
id companyName
1 xxxxxxxxxxxxx
-
5. Re: Help With Inheritance
wdfink Jun 21, 2011 2:25 PM (in response to rread)Mmm,
maybe two tables related to TPerson with a 0..1-1 relation might be a solution.
And TPerson contain a method isCustomer() { return custAddon != null } => custAddon.getBirthday()
And the same for supplier.
-
6. Re: Help With Inheritance
rread Jun 24, 2011 10:26 AM (in response to wdfink)It seems the problem is in the mapping, cause acording to recomendations, each record of TPerson should have a relations ship with only one of the 2 tables(TSupplier or TCostumer) exclusively, and this because when the SQL Query is generated is contains and explicit INNER JOIN.
A Examplo of the problem :
Lets Asume a ORACLE 11g database,
there is a Record of TCostumer with id 1, and there still no record in TSupplier.
we would have
TPerson
id name
1 xxxxxxxx
TCostumer
id birthdate
1 xx/xx/xxxx
TSupplier
id companyName
so you have a registerd client, and this client is not yet a supplier.
But it so happen that one day this client opens a bussiness and
has to be register as a supplier with out lossing his rol as client.
So now that we understand the problem we proceed:
1.- We check if there exists a supplier with id 1, at this moment
the Generated SQL would be a
"Select p.id, p.name, s.companyName from TPerson p,TSupplier s where p.id=s.id",
in this case the result would be that it does not exists, cause its a inner join and there
does not exists a record in both tables.
2.- even so we can verified that there exits a person, in this case the SQL would
be something like
"Select p.id, decode(p.id,s.id,"Supplier.class",c.id,"Costumer.class") from TPerson p, TSupplier s, TCostumer c where p.id=s.id(+) and p.id=c.id(+)"
and the result would be that the record is found in TCostumer,
but the requested entitie was TSupplier wich would result in a type compatibility error, and that would happen
cause we where triying to look for a abstract Person and than a LEFT JOIN is applied for both tables (TCostumer, TSupplier)
3.-But even so, we insist and we try to create a new Supplier, we call new Supplier(), we do the required sets,
and the we execute persist. the result would be a duplicated PK Error, that because we where triying to insert into
both tables, (TPerson and TSupplier), considering that acording to step 1 that entity does not exists.
Hopes this explains the problem a little more clearly.