Beauty of Challenge

Must be required getter / setter method for hibernate’s Entity?

December 26, 2007 · Leave a Comment

No.

Hibernate must not require getter/setter method for Entity if using that field access type.

We possibly configure field access type

1. <hibernate-mapping default-access=”field|property|ClassName” >

2. <property access=”field|property|ClassName” >

3. @AccessType(“field|property|ClassName”)

If you using field access type, only can use field.

@Entity
@AccessType(“field”)
public class EntityExample {

@Id
private String id;

@ManyToOne
private AnotherEntity friend;


}

This time directly access to field by Reflection.

But consider from a different standpoint that problem why using getter/setter?

It may be considered point of view that how use Entity object.

If Entity is (rich) domain object, may require getter and setter method.

But Entity is only used to data container(or DTO), may not require setter method.

We had remove misunderstanding to certainly require getter/setter method when using Hibernate!

Categories: hibernate
Tagged:

0 responses so far ↓

  • There are no comments yet...Kick things off by filling out the form below.

You must be logged in to post a comment.