Sunday, August 10, 2014

Upgrading Spring 3.x and Hibernate 3.x to Spring Platform 1.0.1 (Spring + hibernate 4.x)

I recent volunteered to upgrade our newest project to the latest version of Spring Platform. What Spring Platform gives you is dependency & plugin management across the whole Spring framework's set of libraries.

Since we had fallen behind a little the upgrade did raise some funnies. Here are the things I ran into:

Maven:
Our pom files were still referencing:
hibernate.jar 
ehcache.jar 
These artefacts don't exit on the latest version, so replaced those with
hibernate-core.jar  and ehcache-core.jar

We also still use the hibernate tools + maven run plugin to reverse engineer our db object.
This I needed to update to a release candidate:


Hibernate:
The code: "Hibernate.createBlob"... no longer exists

replaced with:

On the HibernateTemplate
return types are now List; not element...So needed to add casts for the lists being returned.

import org.hibernate.classic.Session;
replaced with:
import org.hibernate.Session;

Reverse engineer works a little differently...
Assigns Long to numeric...
Added:

Possible Errors:

  • Caused by: org.hibernate.service.UnknownUnwrapTypeException: Cannot unwrap to requested type [javax.sql.DataSource]
Add a dependency for c3p0:

And configure the settings in the cfg.xml for it:
  • Caused by: java.lang.ClassNotFoundException: org.hibernate.engine.FilterDefinition

Probably still using a reference to hibernate3 factory / bean somewhere, change to hibernate4:
org.springframework.orm.hibernate3.LocalSessionFactoryBean
org.springframework.orm.hibernate3.HibernateTransactionManager

  • Caused by: java.lang.ClassNotFoundException: Could not load requested class : org.hibernate.hql.classic.ClassicQueryTranslatorFactory There is minor change in new APIs, so this can be resolved by replacing property value with:

org.hibernate.hql.internal.classic.ClassicQueryTranslatorFactory.

Spring:
Amazingly some of our application context files still referenced the Spring DTD ... replaced with XSD

In Spring configs added for c3p0:

Spring removed the "local"=: so needed to just change that to "ref"=

Spring HibernateDaoSupport no longer has: "releaseSession(session);", which is a good thing so was forced to update the code to work within a transaction.

Possible Errors:

  • getFlushMode is not valid without active transaction; nested exception is org.hibernate.HibernateException: getFlushMode is not valid without active transaction

Removed from hibernate properties:
     <prop key="hibernate.current_session_context_class">thread</prop>

Supply a custom strategy for the scoping of the "current"Session. See Section 2.5, “Contextual sessions” for more information about the built-in strategies

  • org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.

Another option is :
<bean id ="productHibernateTemplate" class="org.springframework.orm.hibernate4.HibernateTemplate">
<property name="sessionFactory" ref="productSessionFactory"/>
<property name="checkWriteOperations" value="false"/>
</bean>

  • java.lang.NoClassDefFoundError: javax/servlet/SessionCookieConfig
Servlet version update:

  • Then deploying on weblogic javassist: $$_javassist_  cannot be cast to javassist.util.proxy.Proxy

The issue here was that there were different versions of javassist being brought into the ear. I all references removed from all our poms, so that the correct version gets pulled in from from Spring/Hibernate...

and then configured weblogic to prefer our version:




13 comments:

  1. Telangana DSC Recruitment Notification 2016

    Thanks for author for providing amazing information in the post..................

    ReplyDelete
  2. Mass Effect 4 Andromeda. But instead of naming it Mass Effect 4,
    they have added the name of a famous galaxy which says a lot about what to expect from this game.
    If you are a hardcore gamer then this game is surely going to interest you. For more info, you can take a look Mass Effect 4 release date

    ReplyDelete
  3. Online tutoring could be a one stop resolution for college students United Nations agency want in-depth information on any subject during a short span of your time. Students will access it by following some simple steps. visit the site

    ReplyDelete
  4. That is why if you're one in every of those those who need to completely perceive finance theories and formulas, there ar some sites that may give you with finance assignment facilitate. more

    ReplyDelete
  5. Dedicated SQL Hosting refers To dependable database hosting services provided for a variety of customers. Dedicated SQL Servers differ in their specifications based upon the plan chosen By the client. Information stored in the SQL database could be accessed through The web-based SQL enterprise manager. helpful link will help you to know more.

    ReplyDelete
  6. Every PC gamer owns a mouse, but not every PC gamer owns the best gaming mouse for their favorite FPS games, or the best ambidextrous mouse for playing left-handed. Check out the top 10 gaming mouse

    ReplyDelete
  7. This information you give us is great.

    ReplyDelete
  8. The difference between Spring and Hibernate is that spring is a complete framework and Hibernate is integrated into to Spring framework. The best part of our Alzheimer’s Care Services in Villages FL is the customized memory care service that ensures your loved one is well cared for while living at home.

    ReplyDelete
  9. It unlocks enhanced features, performance, and compatibility with the new spring. How Can Uninstall This process may pose challenges, but the benefits in terms of stability and functionality are well worth the effort.






    ReplyDelete

Popular Posts

Followers