Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate mapping: ignore a super class field

I have a class A and class B

public class A{
int f1;
int f2;
int f2;
}

public class B extends A{
}

my question is how to ignore a field for example 'f2', in the table mapped to B?

like image 458
Amir Avatar asked Apr 27 '15 11:04

Amir


1 Answers

I will try to answer assuming the edit I have made to your post is approved. In the code below I am ignoring the field f2 from class A i.e. superclass of B using AttributeOverride.

@Entity
@AttributeOverride(name = "f2", column = @Column(name = "f2_col", insertable = false, updatable = false)
public class B extends A{
}

If you want to read about it further, refer to AttributeOverride.

AttributeOverride with insertable = false, updatable = false should help, but it also depends on your inheritance strategy. It just helps making mapped fields inherited from a superclass transient, so that some other subclass can use it but it will be ignored for this particular sub class.

like image 94
Viraj Nalawade Avatar answered Sep 27 '22 23:09

Viraj Nalawade