-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Migrating from Hibernate 1.6 to 3.1.3
PostPosted: Wed Oct 11, 2006 2:56 pm 
Newbie

Joined: Wed Oct 11, 2006 2:48 pm
Posts: 4
Hibernate version: 3.1.3

Hi,

I just took over a project which was developed about 2 years ago and which uses Hibernate 1.6. My first task is to migrate it to Hibernate 3 so that we can use the new features. While I managed to update most of the changes I have a couple of issues left that I can not figure out what are the new classes to use or method of doing it. I tried to search alloevr the interent as well as the Wiki, Hibernate forums and so on.

The problem is that the classes in question use import hbm2java.AbstractRenderer; hbm2java.ClassMapping; and hbm2java.FieldProperty;

Here is one of the classes:

Code:

* Created on May 13, 2004
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package com.diatem.util.codegenerator;

import java.io.PrintWriter;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.hibernate.tool.hbm2java.AbstractRenderer;
import org.hibernate.tool.hbm2java.ClassMapping;
import org.hibernate.tool.hbm2java.FieldProperty;

/**
* @author luke
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class BusinessObjectIncludesGenerator extends AbstractRenderer {
    protected String savedToPackage;
    protected String savedToClass;
    protected ClassMapping cmap;
    protected Map class2classmap;
    protected PrintWriter writer;

    /**
     *
     */
    public BusinessObjectIncludesGenerator() {
        super();
    }
   
    /* (non-Javadoc)
     * @see org.hibernate.tool.hbm2java.Renderer#render(java.lang.String, java.lang.String, org.hibernate.tool.hbm2java.ClassMapping, java.util.Map, java.io.PrintWriter)
     */
    public void render(
        String savedToPackage,
        String savedToClass,
        ClassMapping classMapping,
        Map class2classmap,
        PrintWriter writer)
        throws Exception {
       
        this.savedToPackage = savedToPackage;
        this.savedToClass = savedToClass;
        this.cmap = classMapping;
        this.class2classmap = class2classmap;
        this.writer = writer;
       
//        writeHelperMethods();
//        writer.println();
//        writer.println();
//        writer.println();
        writeBeanInterfaceDeclarations();
        writer.println();
        writer.println();
        writer.println();
        writeBeanImplementations();

    }
   
    protected void writeHelperMethods() {
        writer.println("/*###  START HELPER METHODS FOR " + cmap.getFullyQualifiedName() + " ###*/");
        List fields = cmap.getFields();
        if (fields != null) {
            for (Iterator it = fields.iterator(); it.hasNext(); ) {
                FieldProperty f = (FieldProperty) it.next();
                if (GeneratorUtil.shouldUsePersistenceHelper(f)) {
                    writeHelperMethod(f);
                    writer.println();
                }
            }
        }
        writer.println("/*###  END HELPER METHODS FOR " + cmap.getFullyQualifiedName() + " ###*/");
    }
   
    protected void writeHelperMethod(FieldProperty f) {
        writer.println("    public " + getGetterSignature(f) + " throws DAOException {");
        writer.println("        " + f.getClassType() + " ret;");
        writer.println();
        writer.println("        try {");
        writer.println("            ret = (" + f.getClassType() + ") utilities." + getGetterCall(f) + ";");
        writer.println("        } catch (RemoteException e) {");
        writer.println("            e.printStackTrace();");
        writer.println("            throw new DAOException(e);");
        writer.println("        }");
        writer.println("        return ret;");
        writer.println("    }");
    }
   
    protected void writeBeanInterfaceDeclarations() {
        writer.println("/*###  START BEAN INTERFACE FOR " + cmap.getFullyQualifiedName() + " ###*/");
        List fields = cmap.getFields();
        if (fields != null) {
            for (Iterator it = fields.iterator(); it.hasNext(); ) {
                FieldProperty f = (FieldProperty) it.next();
                if (GeneratorUtil.shouldUsePersistenceHelper(f)) {
                    writeBeanInterfaceDeclaration(f);
                    writer.println();
                }
            }
        }
        writer.println("/*###  END BEAN INTERFACE FOR " + cmap.getFullyQualifiedName() + " ###*/");
    }
   
    protected void writeBeanInterfaceDeclaration(FieldProperty f) {
        writer.println(getGetterSignature(f) + " throws DAOException, RemoteException;");
    }
   
    protected void writeBeanImplementations() {
        writer.println("/*###  START BEAN METHODS FOR " + cmap.getFullyQualifiedName() + " ###*/");
        List fields = cmap.getFields();
        if (fields != null) {
            for (Iterator it = fields.iterator(); it.hasNext(); ) {
                FieldProperty f = (FieldProperty) it.next();
                if (GeneratorUtil.shouldUsePersistenceHelper(f)) {
                    writeBeanImplementation(f);
                    writer.println();
                }
            }
        }
        writer.println("/*###  END BEAN METHODS FOR " + cmap.getFullyQualifiedName() + " ###*/");
    }

    protected void writeBeanImplementation(FieldProperty f) {
        writer.println("    public " + getGetterSignature(f) + " throws DAOException {");
        writer.println("        PersistentSession sess = null;");
        writer.println("        sess = new PersistentSession();");
        writer.println("        try {");
        writer.println("            if (!Hibernate.isInitialized(owner." + f.getGetterSignature() +")) {");
        writer.println("                sess.getPersistentSession().update(owner);");
        writer.println("                Hibernate.initialize(owner." + f.getGetterSignature() + ");");
        writer.println("            }");
        writer.println("        } catch (HibernateException e) {");
        writer.println("            e.printStackTrace();");
        writer.println("        } finally {");
        writer.println("            sess.close();");
        writer.println("        }");
        writer.println();
        writer.println("        return owner." + f.getGetterSignature() + ";");
        writer.println("    }");
    }

    protected String getGetterSignature(FieldProperty f) {
        return f.getClassType() + " " + f.getGetterSignature().substring(0, f.getGetterSignature().length()-2) + "(" + cmap.getClassName() + " owner)";
    }
   
    protected String getGetterCall(FieldProperty f) {
        return f.getGetterSignature().substring(0, f.getGetterSignature().length()-2) + "(owner)";
    }
   
}



Any help will be greatelly apreciated.

Thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.