MySQL 5 / MySQL 4.1 + Hibernate 3.2.4sp1
hello to all.
I'm was using mysql 5 + hibernate 3.2.4sp1 + spring 2.0.6
no problem
the problem is when i switched my db to mysql 4.1
i my changed dialect to
Code:
hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect
and one of my code stops working
test case
Code:
@Test
public void testRegisterValidMailButTooLong() {
assertEquals(0, userCount());
final User user = new User();
user.setName("name");
user.setMail(StringUtils.repeat("X", 1024) + "@aol.com");
assertEquals(0, userCount());
boolean register = userService.registerUser(user);
assertEquals(false, register);
assertEquals(0, userCount());
}
service
Code:
@Transactional
public boolean registerUser(final User user) {
boolean result;
final String rawPass = user.getPassword();
final String encoded = passwordEncoder.encodePassword(rawPass, null);
user.setPassword(encoded);
user.setRegistrationDate(new Date());
try {
userDAO.add(user);
result = true;
} catch (DataIntegrityViolationException e) {
log.error(e);
result = false;
} catch (DataAccessException e) {
log.error(e);
result = false;
}
return result;
}
and dao
Code:
try {
final Serializable id = session.save(object);
session.flush();
return id;
} catch (InvalidStateException e) {
session.clear();
session.flush();
throw new DataIntegrityViolationException("failed validation", e);
} catch (HibernateException e) {
session.clear();
session.flush();
throw e;
}
i've debugged and stepped over the code
the insert operation does not happen until after the service code has exited.
but the insert operation should already be cleared.
note: this happens as expected (no records inserted) on MySQL 5, but the record gets inserted (despite being truncated), on MySQL 4.1
any help?