facebook

Hibernate Reverse Generation and merge

  1. MyEclipse Archived
  2.  > 
  3. Database Tools (DB Explorer, Hibernate, etc.)
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #286621 Reply

    Douglas M Hurst
    Participant

    Is this correct or a bug. This is what is generated

    public class MonitorScheduleDAO extends HibernateDaoSupport {
    private static final Log log = LogFactory.getLog(MonitorScheduleDAO.class);
    // property constants
    public static final String TEST = “test”;
    public static final String NOTIFICATION = “notification”;
    public static final String PERIOD = “period”;
    public static final String PERIOD_FREQUENCY = “periodFrequency”;

    This is the composition of my data table

    schedule_id INTEGER
    test VARCHAR(45)
    last_run DATETIME
    notification VARCHAR(300)
    period CHAR(1)
    period_frequency INTEGER

    Is it normal for nothing to be generated for DATEEIME fields

    Also, I’m finding that all the retrieval methods seem to work, but I can’t get merge() to work. Every indication is that it is successful except the data table IS NOT being updated. I’ve purposedly changed field data to try to check this. I tried manually adding an “update()” method which Hibernate seemed to be happy with, but alas, it didn’t work either.

    In the sample program SpringHibernateProject, the update a name

    /* 6. Update the user */
    userLoadedFromDB.setFirstName(“Johnathan”);
    persistenceLayer.updateUser(userLoadedFromDB);

    Since I only update the last_run (DATETIME), I can’t update in this manner because the RE didn’t generate anything for that field?

    I thought this might be because the transaction was not being committed, but I see no commit() method being generated by the RE either.

    #286633 Reply

    Douglas M Hurst
    Participant

    Another thing I’m not understanding

    In the HibernateSpringProject (from the tutorial), this works OK on screen (console). It’s obviously saving/adding the record. As I step through it in debug, it’s obvsiously retrieving the original recorded added and it’s obviously changing the record, “Johnathon” but the problem is, I have this pointing to my localhost:3306/test database table, and I NEVER see the record in that table?

    Is this some sort of a commit issue?

    #286634 Reply

    Douglas M Hurst
    Participant

    FYI, I commented out the line…

    persistenceLayer.deleteUser(user);

    … so it seems there should have been a record in the DB with the name Johnathon.

    #286636 Reply

    Douglas M Hurst
    Participant

    And also, FYI, in my adaptation of the HibernateSpringProject (from the tutorial), I find that when I update/merge my data, then retrieve it by id, it DOES have the updated information, but again, it’s NOT being committed to the database.

    So my question becomes, what is required to make the commitment?

    #286656 Reply

    Douglas M Hurst
    Participant

    No matter what I do try try to get a session or begin a transaction I’m getting an error
    Every attempt to get the Session results in

    No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here

    #286664 Reply

    Douglas M Hurst
    Participant

    Looking on the internet, I found the following modification to HibernateSpringProject in

    UserDAO

    Session session = getHibernateTemplate().getSessionFactory().openSession();
    Transaction tx = session.beginTransaction();
    session.saveOrUpdate(transientInstance);
    tx.commit();
    session.close();

    This works, but the only problem is, I think it would be overwritten evertime you RE on the table. I suppose I could modify the template, but why wouldn’t a beging tran and commit be included in a normal RE?

    #286666 Reply

    Douglas M Hurst
    Participant

    I solved this outside the RE generated DAO, but I’m not sure if it’s the correct way to do it. It stil seems like it out to work as generated, but obviously it’s not. I found the fix at…

    http://code.google.com/p/hibernatespringproject/source/browse/trunk/src/com/myeclipse/hibernatespring/UserDAO.java?r=6

    … who had placed pretty much these same lines in the RE code. I moved them over to the persistence layer.

    public User merge(User detachedInstance) {
    log.debug(“merging User instance”);
    try {
    Session session = getHibernateTemplate().getSessionFactory().openSession();
    Transaction tx = session.beginTransaction();
    session.saveOrUpdate(detachedInstance);
    tx.commit();
    session.close();
    //User result = (User) getHibernateTemplate()
    // .merge(detachedInstance);
    log.debug(“merge successful”);
    return result;
    } catch (RuntimeException re) {
    log.error(“merge failed”, re);
    throw re;
    }
    }

Viewing 7 posts - 1 through 7 (of 7 total)
Reply To: Hibernate Reverse Generation and merge

You must be logged in to post in the forum log in