• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What are the differences between field- and property-based persistence

 
Mellon Sun
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Entity
public class Category {
@Id
public Long id;
public String name;
public Category(){}
}

@Entity
public class Category{
private Long id;
private String name;

@Id
public Long getId(){...}
public String getName(){...}
}

Besides the encapsulation and data hiding, are there other differences like performance between these two strategy?

[ July 31, 2008: Message edited by: Mellon Sun ]
[ July 31, 2008: Message edited by: Mellon Sun ]
 
krishna bulusu
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think it affects the performance.
Its completely depends upon your requirement.
Lets say if you want to manipulate the fields upon retrieving, then go for property based style.Otherwise, go for field based style.
I prefer property based as it gives you extra facilities like data hiding, manipulating the fields etc etc...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic