views:

116

answers:

2
@MappedSuperclass
public abstract class BaseAbstract implements Serializable{

 private static final long serialVersionUID = 1L;

 protected String test = //some random value;

 public String getTest() {
  return test;
 }

 public void setTest(String test){
  this.test = test;
 }
}


@Entity
public class Artist extends BaseAbstract
{
  private static final long serialVersionUID = 1L;
  private Integer id;

        @override
 @Transient
 public String getTest() {
  return test;
 }
.....
}

My question is... when i am trying to do any operation on the artist, along with id and name, test is also getting saved which should not be the case...

if i add the same transient on the baseabstract class getTest() method, i see test column NOT getting created(ideally what it should happen) but if i try to override the method with adding annotaion in the sub class it creates the test column...

I dont know why this is happening since when hibernate is creating the artist object and checks for annotations, it should see the transient annotation present on the getTest() of artist method...and should not create a column in the database...

Let me know if you need any clarification....

Any response on this is greatly appreciated....

Thank you

+1  A: 

I'd suggest putting @Transient on the protected String test field itself, not on the method.

Bozho
A: 

When you mark a Parent class as @MappedSuperclass, you are saying

Persist its properties for each subclass

As your Parent class is abstract (You can not instantiate an abstract class), do as follows

@MappedSuperclass
public abstract class BaseAbstract implements Serializable {

    @Transient
    public String getTest() {

    }

}

And if you do not want to persist your subclass getTest property, do again

@Entity
public class Artist extends BaseAbstract {


    @Transient
    public String getTest() {

    }

}

Nothing else!

Arthur Ronald F D Garcia