• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Table per class heirarchy

 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,

Why is that the subclass elements cant have NOT NULL set for their attributes? I'm failing to understand this!
 
Danilo Dadonas
Ranch Hand
Posts: 59
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks man!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic