0

I'm using @NotNull to define some atributes, but i want to use on relations as well. So i did

@NotNull(message = "Região não pode ser nula")
@JoinColumn(name = "regiao_id", referencedColumnName = "regiao_id")
@ManyToOne(optional = false)
private Regiao regiaoId;

Just like i would do

@NotNull(message="O nome não pode ser nulo")
@Size(min = 1, max = 10)
@Column(name = "nome")
private String nome;

Using on a String it works fine, but it doesn't work on my relation objects, so i end up having to validate whit something like if(foo.regiaoId() != null) , can't i just make use of the @NotNull on situations like this as well?

To make it easy to understand i have an xhtml form where i dont want my selectOneMenu to be null

my xhtml

            <p:outputLabel value="Região:" for="regiaoCombo" />
            <p:selectOneMenu id="regiaoCombo" value="#{equipamentoBean.equipamento.regiaoId}" converter="omnifaces.SelectItemsConverter">
                <f:selectItem itemLabel="Selecione" itemValue="#{null}"></f:selectItem>
                <f:selectItems value="#{equipamentoBean.regioes}"></f:selectItems>
            </p:selectOneMenu>
            <p:message for="regiaoCombo"/>

Since i don't want to add to validate the nullable on my jsf, what would be the best way? Is there a way to use @NotNull on a object that belongs to a persistence class?

REFs using javax.validation.constraints.NotNull

Best way to add a "nothing selected" option to a selectOneMenu in JSF

Community
  • 1
  • 1
prabello
  • 556
  • 2
  • 14
  • 31

1 Answers1

0

Try to use in conjunction with @NotNull

@Basic(optional = false) or @Column(nullable = false)

Here is a link to a clear and simple JPA documentation that might also help you http://www.objectdb.com/api/java/jpa/annotations

Lethe
  • 41
  • 5
  • Doesn't really do what i want, i want to use as i use @NotNull as a validation bean, i tried both, but still the same results... – prabello Sep 29 '14 at 22:05