Tremend Tech Blog

"Software is a great combination between artistry and engineering. When you finally get done and get to appreciate what you have done it is like a part of yourself that you've put together." (Bill Gates)

Looking for software experts?

Need an expert advice on software development? Need consulting work done in time and at high standards? Tremend has the right solution for you.

We can provide expertise in:
  • high traffic and complex content website infrastructures
  • website development-advanced web programming with PHP, .NET, Java, Flash/Flex, Ajax

Our friends

Hibernate schema maintenance

July 31st, 2007 by Ioan Cocan

Hibernate provides a nice way to keep your DB schema in sync with the model. At least 2 choices are available:

- have the hibernate.hbm2ddl.auto set to auto during development

- use various utilities: SchemaExportTask or HibernateToolTask(newer) to generate the full DB schema

For development, first choice worked except for one thing: index creation. All columns were properly created but no index defined. As I found no workaround to that, the only solution was to generate the whole schema.

What if the Hibernate model mixed hbm.xml files with annotations (reused components, mostly)? The SchemaExportTask or HibernateToolTask do not handle the mixed model not to mention the integration with Spring and the missing hibernate.cfg.xml file required by HibernateToolTask.

Only one solution: go to the code and generate the schema by calling the code directly. Easy task actually, I’ve placed the code in a quick Junit test with Spring auto-injection:

/**
 * Maintains DB schema
 *
 * @author icocan
 */
public class SchemaMaintenanceTest extends BaseCommitTestCase {

    private LocalSessionFactoryBean localSessionFactoryBean;

    public void testExportDDL() {
        Configuration configuration = localSessionFactoryBean.getConfiguration();
        SchemaExport export = new SchemaExport(configuration);
        export.setOutputFile("sql.ddl");
        export.setDelimiter(";");
        export.execute(false, false, false, false);
    }

    public void setLocalSessionFactoryBean(LocalSessionFactoryBean localSessionFactoryBean) {
        this.localSessionFactoryBean = localSessionFactoryBean;
    }
}

Share/Save

Posted in Java, General | 1 Comment »

DWR, JSON and IE6: beware keywords

July 20th, 2007 by Ioan Cocan

Spent quite a bit of time investigating an “IE bug”. What happened: a particular AJAX request would work fine in Firefox but nothing would happen in IE6. Obvious steps were to monitor request and response (all fine), JS imports in files (all fine).

The final explanation was quite simple: that particular object (Customer), contained a field called “function”. The JSON string returned by DWR was correctly interpreted by FF but would make IE6 hang. The simple solution: rename the field and beware any other JS keywords.

Share/Save

Posted in Java, General | 1 Comment »