Traditionally I have always made by Hibernate entities as follows:
@Entity
@Table(name = "my_table")
@SuppressWarnings("serial")
public class MyEntity extends Serializable
{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private long id;
@Column(name = "name")
private String someName;
@Column(name = "description")
private String description;
and getters and setters have looked like:
public String getSomeName()
{
return someName;
}
public void setSomeName(String someName)
{
this.someName = someName;
}
public String getDescription()
{
return description;
}
public void setDescription(String description)
{
this.description = description;
}
followed by Eclipse generated hashcode, equals, and toString methods.
Now I am being asked to change my setters to be as follows:
public MyEntity setSomeName(String someName)
{
this.someName = someName;
return this;
}
public MyEntity setDescription(String description)
{
this.description = description;
return this;
}
This is so we can do chaining:
MyEntity entity = new MyEntity().setSomeName("x").setDescription("y");
This doesn't break my unit tests for CRUD, the DAO still seems to work fine.
What is annoying that with Eclipse, I can whip out getters/setters very quickly, but now I need to adjust all my setters with "return this;"
First ... I am not sure, but is this the new normal for java 8? Will this have any adverse affects in the long wrong, is this going to take up more memory, or is this going to be highly efficient and I should do this?
I've been doing Java since JDK 1.3 and the past 15 years, and I know each new technology advance has it's quirks. I was just wondering if there were any here?
Thanks!