Results 1 to 3 of 3

Thread: MySQL 5 / MySQL 4.1 + Hibernate 3.2.4sp1

  1. #1
    Join Date
    Jan 2007
    Location
    Kuala Lumpur, Malaysia
    Posts
    138

    Default 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. #2
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,796

    Default

    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);
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

  3. #3
    Join Date
    Jan 2007
    Location
    Kuala Lumpur, Malaysia
    Posts
    138

    Default

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •