- This topic has 6 replies, 1 voice, and was last updated 16 years, 3 months ago by Douglas M Hurst.
-
AuthorPosts
-
Douglas M HurstParticipantIs 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 INTEGERIs 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.
Douglas M HurstParticipantAnother 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?
Douglas M HurstParticipantFYI, I commented out the line…
persistenceLayer.deleteUser(user);
… so it seems there should have been a record in the DB with the name Johnathon.
Douglas M HurstParticipantAnd 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?
Douglas M HurstParticipantNo 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 inNo Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
Douglas M HurstParticipantLooking 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?
Douglas M HurstParticipantI 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…
… 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;
}
} -
AuthorPosts