0

As shown below, i have the object Car with 2 persistence attributes:

public  class Car {

@Column(name = "COLOR")
protected String color;

@Column(name = "BRAND")
protected String brand;
}

All objects that extends from Car use the 2 attributes, but in some the them, i want to exclude one or all attributes. For example:

public  class SpecialCar extends Car{
    //how to tell here that i don't want to have Brand column

}

Thx for help

Dupont
  • 333
  • 4
  • 16
  • Well, I don't know if that's possible coz if anything is `protected`or `public` or has no modifier, then it **will** be inherited. If something is `private` it is **not** inherited. – Hungry Blue Dev Jan 12 '14 at 16:35
  • You should check out the @AttributeOverride annotation from hibernate. e.g. as used in: http://viralpatel.net/blogs/hibernate-inheritance-table-per-concrete-class-annotation-xml-mapping/ – Ben Jan 12 '14 at 16:37
  • 1
    Don't do that. If a `SpecialCar` extends a `Car`, then, for all that matters, it must behave as a `Car` (if a `Car` has brands, so it also must have). If you don't do like that, it is a violation to the [Liskov Substitution Principle](http://en.wikipedia.org/wiki/Liskov_substitution_principle) of OO software, which leads to complicated and hard to understand/maintain software. If you still want to have the `SpecialCar` being different, then I suggest using [composition instead of inheritance](http://en.wikipedia.org/wiki/Composition_over_inheritance). – acdcjunior Jan 12 '14 at 17:25

2 Answers2

0

If you do not want it in SpecialCar then, to me, it means, it should not be in Car at all. Can't you simply remove it from Car?

Eugene
  • 117,005
  • 15
  • 201
  • 306
0

I think that this is answered allready here:

Disabling inherited method on derived class

I also think that is not possible, but they give you a nice trick

Community
  • 1
  • 1
anquegi
  • 11,125
  • 4
  • 51
  • 67