0

Im working on a jsf + hibernate project, I have a bean which should be validate by hibernate before saving into database, This Bean has 5 fields which should be all validate by @NotNull. My problem is : I have 2 interfaces : the first one I need to fill those 5 fields in my first interface : the result => the save is done with no problem because 5 fields are not null in this case , But in my second interface I have only 3 fields to fill => result : the save is not working because the rest of 2 fields are null in this case and are not filled = In second interface.

Find here my bean .

@Entity
@Table(name = "MyBean")
public class MyBean implements Serializable
{

    private static final long serialVersionUID = 1L;

    @Id
    @Column(name = "ID")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;


    @NotNull
    @Size(min = 1, max = 15)
    @Column(name = "SN")
    private String serialNumber;


    @NotNull
    @Column(name = "MANUFACTURER")
    private String manufacturer;


    @NotNull
    @Column(name = "TYPE")
    private String type;



    @NotNull
    @Column(name = "MINIMUM_STOCK")
    private Integer minimumStock;

    @NotNull
    @Column(name = "MAXIMUM_STOCK")
    private Integer maximumStock;

// getters + setters

Any proposition or idea from your part . Thank you in advance

majdi
  • 43
  • 1
  • 9
  • 1
    The answer is in the question: either you need to fix the second UI because it makes no sense to save an entity with 2 null properties, or you need to accept null values for these 2 properties. Or the second UI shouldn't save that entity, but a different one, which doesn't have the same validation constraints (i.e. a Draft rather than a MyBean, for example) – JB Nizet Dec 04 '17 at 15:11
  • yes you are right !!! But in my application I need to work on the same Bean, I have 2 UI the first one with 5 input and the second with just just 3 input of them . This is the logic of the app :( – majdi Dec 04 '17 at 15:18
  • Then either you should save default values for the 2 absent properties, or you should relax the validation, and allow null. – JB Nizet Dec 04 '17 at 15:20
  • save default values => thats mean affect to them some value or how ? thank you – majdi Dec 04 '17 at 15:46

0 Answers0