Forums Register Login

Table per class heirarchy

+Pie Number of slices to send: Send
Guys,

Why is that the subclass elements cant have NOT NULL set for their attributes? I'm failing to understand this!
+Pie Number of slices to send: Send
Hi, Jothi. Supose that we have the following classes:

-----------
Person
-----------
name
homeAddress
-----------

----------
Teacher extends Person
----------
university
salary
----------

----------
Student extends Person
----------
ipod
----------

the table than is:

--------------
Person
--------------
name
home_address
university
salary
ipod
--------------

Considerete the Java code:

Person person;

person = new Teacher("Dadonas","76th Street, 1234", "Harvard", "10,000");

HibernateUtil.getSession().saveOrUpdadte(person);

If the field ipod of the table was marked with not null, a null exception would be throwed.

If we do this:

person = new Student("Dadonas","76th Street, 1234", "MyiPod");

HibernateUtil.getSession().saveOrUpdadte(person);

If the fields university and salary was marked with not null, a null exception would be throwed.

The fields in this case can't be not null.

I hope it helps you.
+Pie Number of slices to send: Send
Thanks man!
There will be plenty of time to discuss your objections when and if you return. The cargo is this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 640 times.
Similar Threads
Using discriminator on base class with no subclasses
Misleading Inheritance Model names - Java Beat questions
Help with a Mapping
casting
Hibernate @DiscriminatorColumn
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 10:35:53.