Can not persist data model's field into database, but can retrieve it

Suule :

I have a problem when trying to persist a data model class into a database. I have a class like this:

class DataModelClass{
    //some more field etc.

    @Column(name = "number1", nullable = true)
    private Integer number1;

    @Column(name = "number2", nullable = true)
    private Integer number2;

    public DataModelClass(){}

    (...)

    public Integer getNumber2() {
        return number2;
    }

    public void setNumber2( Integer number2 ) {
        this.number2= number2;
    }
}

The second field was added after first one. When to persist object created with this class via:

em.persist(dataModelClass);

A new row in database is created, but only with first field added. The second one is empty. When I am debugging the object dataModelClass has every field set with some integer value. When I am adding a value for number2 through pgAdmin, and then retrieving this row with java code via:

DataModelClass dmc = em.find(DataModelClass.class, 1);

Than dmc.getNumber2() is not empty/null.

Anyone have any ideas what is wrong?

[Edit] Maybe it will help a little more, On data model (DataModelClass) class i got this annotation:

@Entity
@Table(name = "custom_table",
       uniqueConstraints=@UniqueConstraint(name="UK_example_foreign_id", columnNames={"example_foreign_id"})
)
@SequenceGenerator(name = DataModelClass.SEQ_NAME, sequenceName = DataModelClass.SEQ_NAME, allocationSize = 1)

Obviously this field exist in my class

Suule :

The problem was, that after persist there was another query which was updating the database with null value. So the answer was to change this value in update query. Thanks all.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=36274&siteId=1