According to the definition of a immutable object (see this question), I am not pretty sure about whether making setters of a Spring DAO as a only-one-use is a way to assure immutability or not. For instance (dataSource property):
public class MySpringPojoDAO extends JdbcDaoSupport implements IMySpringPojoDAO {
private boolean dataSourceSet = false;
@Override
public void setDataSource(DataSource dataSource){
if (dataSourceSet) {
throw new IllegalStateException("...");
}
dataSourceSet = true;
this.dataSource = dataSource;
}
}
}
In the case it is wrong, what's the way to assure immutability using Spring Framework or IoC ?