I have a class suitable for the builder pattern, there are many parameters, and I would prefer not to use a ton of telescopic constructors.
My problem is that this class is a JPA entity and it is very new to me.
The presence of closed finite data elements causes an error because I am not initialized in the constructor, and as far as I know, JPA requires an empty protected constructor.
Can anyone help? The example would be fantastic, I included the basic code example below, but it is very general. I saved many members and data members to save space / time.
@Entity//(name= "TABLE_NAME") //name of the entity / table name public class Bean implements Serializable { private static final long serialVersionUID = 1L; @Id //primary key @GeneratedValue Long id; private final DateTime date; private final String title; private final String intro; //used by jpa protected Bean(){} private Bean(Bean Builder beanBuilder){ this.date = beanBuilder; this.title = beanBuilder; this.intro = beanBuilder; } public DateTime getDate() { return date; } public String getTitle() { return title; } public static class BeanBuilder Builder{ private final DateTime date; private final String title; //private optional public BeanBuilder(DateTime date, String title) { this.date = date; this.title = title; } public BeanBuilder intro(String intro){ this.intro = intro; return this; } public BeanBuilder solution(String solution){ this.intro = solution; return this; } public Bean buildBean(){ return new Bean(this); } } }
source share