Announcement Announcement Module
Collapse
No announcement yet.
MySQL 5 / MySQL 4.1 + Hibernate 3.2.4sp1 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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?

  • #2
    and one of my code stops working
    is there some error message to share??

    the insert operation does not happen until after the service code has exited.
    weird, should be inserted in
    final Serializable id = session.save(object);

    Comment


    • #3
      i'm sorry, i forgot to mention this.
      the test
      testRegisterValidMailButTooLong
      tries to insert a 1000+ character string to an 80 character column.
      it should fail
      but under mysql 4.1,
      it fails but gets inserted in the doCommit in the
      aop-transactioned proxy
      failing means the data does get inserted but course not the whole data,
      the truncated data

      at
      session.flush();

      the error message pops up, and the
      catch (HibernateException e)
      block gets executed.

      is it common/good practice to do a session.close in a hibernatecallback action?

      in the hibernate docs

      11.2.3. Exception handling
      If the Session throws an exception (including any SQLException), you should immediately rollback the database
      transaction, call Session.close() and discard the Session instance. Certain methods of Session will not
      leave the session in a consistent state. No exception thrown by Hibernate can be treated as recoverable. Ensure
      that the Session will be closed by calling close() in a finally block.

      Comment

      Working...
      X