Is it possible to store a null value of an enumerated attribute in a database?

I am trying to save the null value of an attribute of an enumerated object in Java in Oracle . using JPA TopLink. The code is executed without exception or warning, but the object is not stored in the database.

An entity is defined as follows:

@Entity
public class LetterDoc {
    ...
    @Column(name = "delivery_type", columnDefinition = "VARCHAR2(20)", nullable = true)
    @Enumerated(EnumType.STRING)
    private DocDeliveryTypeEnum deliveryType;
    ...
}

The Enum class DocDeliveryTypeEnum has only the required values.

public enum DocDeliveryTypeEnum {
    NORMAL,
    RECOMMENDED,
    ACKNOWLEDGEMENT
}  

, deliveryType . , null. , .

null, , , VARCHAR2 (20) NULL.

:

LetterDoc let = new LetterDoc();
// settery ostatnich atributu
let.setDeliveryType(null);
try {
    emptyDocDAO.persist(let);
    emptyDocDAO.flush();
} catch (Exception e) {
    // no exception is really catched :(
    log.error(e);
}
// here I have the id of the entity

, . , NoResultException.

, , ? Enum?

, , . , , .

.

+5
2

, null enum.

, , , ?

, .

+1

NullPointerException, . Enum.valueOf() NullPointerException, null.

let.setDeliveryType();

0

All Articles