-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Uexpected behaviour whaen calling super()
PostPosted: Sat Feb 05, 2011 8:30 am 
Newbie

Joined: Mon Jan 31, 2011 2:49 am
Posts: 2
@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorValue("1")
public class InheritanceWithSingleTable {
public InheritanceWithSingleTable(String name) {
this.name = name;
}
private String name;
@Basic(optional=false)
public String getName(){
return name;
}
public void setName(String name){
this.name = name;
}
private long id;
@Id
@GeneratedValue
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
// .....
}

@Entity
@DiscriminatorValue("2")
public class InheritanceWithSingleTableChild extends InheritanceWithSingleTable {
public InheritanceWithSingleTableChild(String name){
super(name);
}
@Override
@Transient
public String getName() {
return "START " + super.getName() + " END ";
}
//...
}

InheritanceWithSingleTableChild child = InheritanceWithSingleTableChild("foo");
// ... save, prerist
// childReladed the child reloaded from DB
String result = childReloaded.getName();
//the expected result would be "START foo END", but I get "START START foo END END "

Assuming that I can not change the classes, only the annotations or XML mappings
//is it possible to get the expected behaviour "START foo END"?


Top
 Profile  
 
 Post subject: Re: Uexpected behaviour whaen calling super()
PostPosted: Sat Feb 05, 2011 1:22 pm 
Newbie

Joined: Fri Jan 07, 2011 7:23 am
Posts: 19
Hi,

use field-based access! If you use property-based access the result of the getter is actually stored in the database.

Robin.


Top
 Profile  
 
 Post subject: Re: Uexpected behaviour whaen calling super()
PostPosted: Sun Feb 06, 2011 4:06 am 
Newbie

Joined: Mon Jan 31, 2011 2:49 am
Posts: 2
Thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.