JSF/Hibernate How do I save null to a database field?

Asked

Viewed 505 times

4

I have an application using Primefaces/JPA-Hibernate/Tomcat8, and I need that when a field on the screen is empty, it will record null in the bank (Postgres). I need this because I have some fields in the database that have Uniquekey, and even when the field is empty on the screen, and save an empty string in the database -> ''

I’m already using the parameter: javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL and it doesn’t seem to work. I already used Convert to nullify the empty String, and also in the works, because when the value reaches my entity the string is empty again and not null. Missing some lib or no how to do this I really want?

  • 1

    default null in the columns? Entity Listener? PrePersist and/or PreUpdate in the entity(s) you need?

  • I made a test using the wildfly and parameter javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL is obeyed! It would be a problem of tomcat8 then?

  • When climbing the Tomcat, include this section in the JVM_OPTION: -Dorg.apache.el.parser.COERCE_TO_ZERO=false. See if it works, it should only affect number, but I remember having problems with it in one version of it.

  • I forgot to mention that I was already using this COERCE_TO_ZERO=false option and it also did not have an effect.

1 answer

0

Puts the default null value in your entity’s field!

private String valor = null;
  • 1

    Null is already the default value of any object.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.