Sleep mode will not persist after saving

Can someone explain why the date "lastAccessed" is not stored in the database in this example and how can I save it in the database? I understand that the do object is an attached object after calling save (), and therefore all modifications should be saved automatically.

Note. "myDate" is saved correctly, so all other spring configuration seems to be correct.

@Transactional(readOnly = false)
public DateObject getOrCreateDateObject(Date myDate) {
    DateObject do = null;

    do = getCurrentDateObject();  // For my tests, this has been returning null

    if (do == null) {
        // create a new object
        do = new DateObject();
        do.setDate(myDate);
        sessionFactory.getCurrentSession().save(do);
    }

    // This does not persist to the database
    do.setLastAccessed(new Date());

    return do;
}

I also tried some of the following combinations (or more) after calling save (). None of these works:

sessionFactory.getCurrentSession().merge(do);  // tried before and after do.setDate(d2)

sessionFactory.getCurrentSession().update(do);

sessionFactory.getCurrentSession().saveOrUpdate(do);

sessionFactory.getCurrentSession().flush();

DateObject doCopy = (DateObject)sessionFactory.getCurrentSession().load(DateObject.class, do.getId());
sessionFactory.getCurrentSession().merge(doCopy);
doCopy.setLastAccessed(new Date());

I hope this is a simple answer that I just don't see. Thanks for the help!

Edit # 1 05/22/2012

, , src/main/resources/META-INF/dateobject.hbm.xml. , , "SELECT * FROM dateObjects" mysql. MY_DATE , LAST_ACCESSED NULL.

<class name="com.example.entity.DateObject" table="dateObjects">
    <id name="id" column="DATE_OBJECT_ID">
        <generator class="identity" />
    </id>
    <property name="date" type="date" column="MY_DATE" />
    <property name="lastAccessed" type="date" column="LAST_ACCESSED" />
</class>

# 2 05/24/2012

SSCCE https://github.com/eschmidt/dateobject. , - ( localhost: 8080/view/test) , lastAccessed , MySQL, , lastAccessed NULL. - , , @Transactional?

+5
2

, do.date db do.lastAccessed , , , . , . @Transient , lastAccessed, ? (, , .)

SSCCE, , - .

:. , . , , , , . github, , . basic-springmvc , , xml . Spring MVC. Spring , , Spring MVC. spring-method-caching, , .

, , , XML. ? . , - listeners SessionFactory, ?

+1

IDENTITY , save() . - INSERT/UPDATE/DELETE SQL ? , , . , , .

0

All Articles