I use the Builder pattern for several classes of my project (multiple arguments, some mandatory, some optional, etc.). These classes are immutable (no setters, deep copy for collections getters).
I am now trying to store those objects in a database using a persistence framework that constructs objects with default constructor + setters. It doesn't like my Builders very much!
I don't want to degrade that setup to POJOs and lose the advantages of the current design (flexibility, immutability, construction security).
I would welcome any feedback on workarounds that can be used in this situation (I could wrap each of these classes but that would double the number of classes and I would rather avoid that).
One post actually points that as a specific disadvantage of the Builder pattern.
EDIT
One answer proposes to use private constructor / setters but that only works if the fields of the class are not final, which is not my case.
FINAL EDIT
Thanks to all.
What I think will be my final solution looks like this and works fine (for the record, I'm using MongoDB + Morphia):
class AClass {
private final String aField;
private final AClass() {
aField = "";
}
//Standard builder pattern after that - no setters (private or public)
}