Red Hat



In Relation To Max Andersen

In Relation To Max Andersen

Seam meetup and JBoss/Red Hat at EclipseCon

Posted by    |       |    Tagged as Seam

Seam meetup

Tonight most of the Hibernate Team and especially the Seam Team met for the first time in person in San Francisco. The next couple of days we will have fun digging into what is next for Hibernate and Seam in particular.

Since this is such a special occurrence you are all invited to help us celebrate this on Friday, March the 2nd in the evening. The details is to be found at this space .

EclipseCon

That is though not the only thing happening around SF; next week there is EclipseCon in Santa Clara where JBoss/Red Hat will have a booth and do the following talks.

Eclipse Linux Distros Project Overview

Autotools demo

OSGi and JBoss Microcontainer

JBoss introduces new open source tools and frameworks for building rich internet applications

Developing an Editor for Directed Graphs with the Eclipse Graphical Editing Framework

Building Rich Internet Applications With Open Source JBoss Frameworks and Tools

and finally, Hibernate Tools

See you there!

Hibernate Tools goes to the movies

Posted by    |       |    Tagged as

Last week we released Hibernate Tools 3.2.0.beta9 and we actually did it twice.

A typo error prevented JPA configurations from working from inside Eclipse thus if you downloaded Hibernate Tools early last week you should go and make sure to get the beta9a version.

Ease of setup

This release has a lot of improvements but the best new feature is definitely that we no longer require users to setup and maintain a separate classpath for the console configuration. Now the classpath of the java project will be used by default.

This makes the setup much easier.

The second best new feature is the full support for JPA configurations (through Hibernate EntityManager). This means that we do also no longer require a hibernate.cfg.xml with a listing of all the annotated classes; the discovery of entities and configuration will be done automatically as long as you have a /META-INF/persistence.xml in your class path.

The last feature I want to mention is again a feature that strips down the need for setup compared to before. HQL editing and validation inside java code is now enabled automatically for projects that has a console configuration associated.

Could it be made easier ? Let us know

Seeing is believing...

To get a feel of the improvements and the overall functionality we created a set of viewlets/movies.

We have done this before and received good feedback on them and most people thought they were informative but too long and boring.

Therefore we made a bunch of small and to the point movies showing the basics of each major/primary feature, allowing you to just see what you are interested in and not get bored too long.

The movies are listed here .

Have fun!

5 years and Hibernate in Copenhagen

Posted by    |       |    Tagged as

I cannot believe it is now 5 years ago I bumped into hibernate, and if you use the way back machine and know the original url(s) of the project you can have a walk down memory lane (yes, the front page were even simpler than what Christian just posted in the very first days of Hibernate; I guess he were being nice towards Gavin and his taste of color)

Browsing through the online mail and forum archives is also tremendous fun; could be interesting to collect some of the milestones and funny anecdotes from these.

Coincidentally I get to celebrate this event by doing the first public training in Copenhagen about Hibernate on 5-6. December, see here for details. I'll look forward to be in the motherland to tell and teach about the current result of the 5 years journey.

I will also be presenting on Hibernate JPA and EJB3 in Copenhagen 4. December at Dansk-IT Java group meeting. You can see the program (in Danish) here .

See you in Copenhagen and to Hibernate and the team: Tillykke med fdselsdagen!

Hibernate Tools 3.2 Beta 7 released

Posted by    |       |    Tagged as

Hibernate Tools 3.2.0.beta7 (http://tools.hibernate.org) have been made available.

Many-to-Many

One new major feature did go into this release (besides bugfixes and minor enhancements). Namely support for many-to-many tables during reverse engineering; so please go check that out if you have been waiting for it and give feedback at our forum and bugreports or enhancement requests at our JIRA .

See screenshots and other noteworthy news here for more information.

Query editing viewlet

I sat down and created a small viewlet of the HQL/JPAQL editing features we added in the previous release. That viewlet can be seen here , and one of the features it illustrates is shown in the following picture:

http://www.hibernate.org/hib_docs/tools/eclipse/newandnoteworthy/completeinsidejava.png

p.s. to enable this feature, you need an open Hibernate Console configuration and remember to enable Hibernate for you java project in the properties of your project.

Hibernate Tools 3.2 Beta 6 released

Posted by    |       |    Tagged as

Hibernate Tools 3.2.0.beta6 (http://tools.hibernate.org) have been made available.

As always the tools are for both Eclipse and ANT.

It was actually released a couple of days ago, but a holiday got in the way of announcing it before now.

The big news for this release is that it is now compatible with Eclipse 3.2 and WTP 1.5, so we have hereby joined or are least compatible with the Callisto train.

Eclipse 3.2 has some new interesting extension points that we have made good use of to e.g. provide HQL code completion and validation inside the java code.

See screenshots and other noteworthy news here for more information.

On a side note, JBossWorld (as always) allowed me to get in contact with alot of users of the Hibernate Tools more directly and that was tremendous fun and interesting - Thanks. I got a lot of new input for new features and enhancements that should make it into future releases.

But remember that even though you did not make it to JBossWorld your feedback and contribution is always welcome at our forum and our JIRA .

Hibernate Tools for Ant, Eclipse and NetBeans

Posted by    |       |    Tagged as

Now that the dust is starting to settle from JavaOne it is time to explain what the announcement from JBoss about joining and endorsing NetBeans means in context of Hibernate Tools.

The core of Hibernate Tools have always and will always be independent of any IDE; these are available via our <hibernate-tool> Ant task.

Hibernate Tools for Eclipse will still be developed and improved. At JBossWorld we will have a release with new features and it will be compatible with Eclipse 3.2 and WTP 1.5 (Callisto), and for the brave the nightly builds should soon be the Callisto-based version.

In other words we are not moving away from Eclipse, we are simply recognizing the great work that the NetBeans community have been doing especially with respect to Java EE 5 tooling.

Thus for NetBeans and Hibernate Tools we gladly accepted a contribution from Leon Chiver which brings some of the Hibernate Tools for Eclipse features to the NetBeans platform, primarily the HQL editor (thank you Leon). We expect to also release a preview of this around JBossWorld.

Already with the initial contribution we have created a shared code set for the HQL code completion which actually resulted in merging both of best worlds and improving the functionality in both the Eclipse and NetBeans plugins.

We plan to align the feature set of the IDE tooling with help from the community and have the plugins share as much code as feasible to allow contributions in both camps to benefit each other. I look forward to hear from you what features you want the most.

There is more news coming and if you are curious come and hear more about them at JBossWorld Las Vegas. I and others from the Hibernate and JBoss IDE Team will be there.

Hibernate Tools 3.1 Beta 5 released

Posted by    |       |    Tagged as

Hibernate Tools 3.1.0.beta5 (http://tools.hibernate.org) have been made available.

The tools are for both Eclipse and ANT.

This version is where the template functionallity is finally based on FreeMarker.

As an extra treat the tools now bundle a FreeMarker plugin to help out when writing custom templates (Thanks to Joe Hudson).

ANT users also get a most-wanted feature, namely removal of the old requirement of having to specify all mapped classes in hibernate.cfg.xml when e.g. generating the schema based on EJB3 annotated classes.

The new <ejb3configuration> support in the ant task allows standard EJB3 persistence packaged projects to be automatically scanned for mappings and then used like any other Hibernate compatible configuration.

See screenshots and other noteworthy news at here for more information.

Hibernate 3.2: Transformers for HQL and SQL

Posted by    |       |    Tagged as Hibernate ORM

People using the Criteria API have either transparently or knowingly used a ResultTransformer . A ResultTransformer is a nice and simple interface that allows you to transform any Criteria result element. E.g. you can make any Criteria result be returned as a java.util.Map or as a non-entity Bean.

Criteria Transformers

Imagine you have a StudentDTO class:

public class StudentDTO {
  private String studentName;
  private String courseDescription;
  
  public StudentDTO() { }
      
  ...
} 

Then you can make the Criteria return non-entity classes instead of scalars or entities by applying a ResultTransformer:

List resultWithAliasedBean = s.createCriteria(Enrolment.class)
  .createAlias("student", "st").createAlias("course", "co")
  .setProjection( Projections.projectionList()
                   .add( Projections.property("st.name"), "studentName" )
                   .add( Projections.property("co.description"), "courseDescription" )
          )
          .setResultTransformer( Transformers.aliasToBean(StudentDTO.class) )
          .list();

 StudentDTO dto = (StudentDTO)resultWithAliasedBean.get(0);  

This is how ResultTransformer have been available since we introduced projection to the Criteria API in Hibernate 3.

It is just one example of the built in transformers and users can provide their own transformers if they so please.

Jealous programming

Since I am more a HQL/SQL guy I have been jealous on Criteria for having this feature and I have seen many requests for adding it to all our query facilities.

Today I put an end to this jealousy and introduced ResultTransformer for HQL and SQL in Hibernate 3.2.

HQL Transformers

In HQL we already had a kind of result transformers via the (select new http://www.hibernate.org/hib_docs/v3/reference/en/html/queryhql.html#queryhql-select) syntax, but for returning non-entity beans it only provided value injection of these beans via its constructor. Thus if you used the same DTO in many different scenarios you could end up having many constructors on this DTO purely for allowing the select new functionality to work.

Now you can get the value injected via property methods or fields instead, removing the need for explicit constructors.

List resultWithAliasedBean = s.createQuery(
  "select e.student.name as studentName," +
  "       e.course.description as courseDescription" +
  "from   Enrolment as e")
  .setResultTransformer( Transformers.aliasToBean(StudentDTO.class))
  .list();

StudentDTO dto = (StudentDTO) resultWithAliasedBean.get(0);

SQL Transformers

With native sql returning non-entity beans or Map's is often more useful instead of basic Object[]. With result transformers that is now possible.

List resultWithAliasedBean = s.createSQLQuery(
  "SELECT st.name as studentName, co.description as courseDescription " +
  "FROM Enrolment e " +
  "INNER JOIN Student st on e.studentId=st.studentId " +
  "INNER JOIN Course co on e.courseCode=co.courseCode")
  .addScalar("studentName")
  .addScalar("courseDescription")
  .setResultTransformer( Transformers.aliasToBean(StudentDTO.class))
  .list();

StudentDTO dto =(StudentDTO) resultWithAliasedBean.get(0);

Tip: the addScalar() calls were required on HSQLDB to make it match a property name since it returns column names in all uppercase (e.g. STUDENTNAME). This could also be solved with a custom transformer that search the property names instead of using exact match - maybe we should provide a fuzzyAliasToBean() method ;)

Map vs. Object[]

Since you can also use a transformer that return a Map from alias to value/entity (e.g. Transformers.ALIASTOMAP), you are no longer required to mess with index based Object arrays when working with a result.

List iter = s.createQuery(
  "select e.student.name as studentName," +
  "       e.course.description as courseDescription" +
  "from   Enrolment as e")
  .setResultTransformer( Transformers.ALIAS_TO_MAP )
  .iterate();

String name = (Map)(iter.next()).get("studentName");

Again, this works equally well for Criteria, HQL and native SQL.

Reaching Nirvana of native sql

We still miss a few things, but with the addition of ResultTranformer support for SQL and the other additions lately to the native sql functionality in Hibernate we are close to reach the Nirvana of native sql support.

Combined with StatelessSession you actually now got a very flexible and full powered sql executor which transparently can map to and from objects with native sql without any ORM overhead.

...and when you get tired of managing the sql, objectstate, lifecycles, caching etc. of your objects manually and want to benefit from the power of an ORM then you got it all readily available to you ;)

Hibernate Tools Demo at EclipseCon

Posted by    |       |    Tagged as

I'll be demo'ing Hibernate Tools at EclipseCon on March 21st. See details here .

It is a 15 minute demo, so will be a quick'n'dirty presentation; but it will give you a good insight on what is available via the plugins currently and what is coming .

Koen Aers will also be presenting A Gentle Introduction to GEF which is used in the basis of the jBPM designer which can be used to model business processes and pageflow for JBoss Seam .

Marshall Culpepper is also present thus the core team behind JBoss Eclipse IDE will be there.

A story about FreeMarker and Velocity

Posted by    |       |    Tagged as Java EE

I have been fed up with Velocity ís ability to ignore and even hide errors and exceptions occurring in the templates used in Hibernate Tools .

This blog tells about why and how FreeMarker became my new interest. If you just want to see the results then go and fetch the code in the TOOLS_FREEMARKER branch...read on to get the full story.

The problems with Velocity

I started to see more and more forum postings and bug reports about issues that were caused by typoís in users templates or even worse errors in the Hibernate Tools. Many of these issues would be solvable within seconds if Velocity would actually tell where in the templates the error occurred and unit tests would have failed if underlying exceptions were exposed; but Velocity simply does not.

I have added every safety-precaution I have been able to apply to Velocity error handling. I have created my own UberSpect and EventHandler implementation that will not allow you to invoke methods that does not exist and I have tweaked the logging settings to be more informative; but it does not (hardly) solve all the problems that can occur.

Logging is excessive in Velocity even at WARN and INFO level, one good reason for this is most likely that the developers know that Velocity is ignoring situations where it should actually fail, thus since there is no easy other way implemented in Velocity they put it in the log for users to discover by accident!

The choice originally fell on Velocity since it was the biggest player around, and I added it naively thinking that the error and log handling could not be that bad if so many people were using it and if there were an issue it would be fixed soon.

As time went by I learned that it was definitely not the case.

The beauty of FreeMarker

Last week I decided to look around for alternatives, the only real alternative I found were FreeMarker; everything else looked either too simple or way to complex for the Hibernate Tools needs. Now that I have spent just 1,5 day converting the existing Velocity templates to FreeMarker Iím more than happy I did.

Here are some examples of the beauty of FreeMarker:

Assume we have the following bean:

public class Table {
 String getName();
}

The bean is available via table in the following code:

${table.namee}

That typo will just be ignored by default in Velocity, with a custom EventHandler it can be convinced to throw an exception which comes out like this:

Caused by: java.lang.IllegalArgumentException: $table.namee is not a valid reference.
at org.hibernate.tool.hbm2x.HibernateEventHandler.referenceInsert([=>HibernateEventHandler.java:11])
        at org.apache.velocity.app.event.EventCartridge.referenceInsert([=>EventCartridge.java:131])
        ... 19 more

No information about which template nor where in the temmplate it went wrong.

In FreeMarker I get the following with no special configuration and custom code:

Expression table.namee is undefined on line 15, column 14 in doc/tables/table.ftl.
The problematic instruction:
----------
==> ${table.namee} [on line 15, column 12 in doc/tables/table.ftl]
----------

Java backtrace for programmers:
----------
freemarker.core.InvalidReferenceException: 
 Expression table.namee is undefined on line 15, column 14 in doc/tables/table.ftl.
    at freemarker.core.TemplateObject.assertNonNull([=>TemplateObject.java:124])
    at freemarker.core.Expression.getStringValue([=>Expression.java:118])
    at freemarker.core.Expression.getStringValue([=>Expression.java:93])
    ...

Nice! And even better, the on line 15, ... works like a link in e.g. Eclipse Console view. Clicking it brings you to the location of the error in the table.ftl. file.

Similar and precise error messages you get if you refer to non existing methods, Just brilliant! The great thing is that if I really wanted FreeMarker to ignore this I could do so by installing a different Exception handler. But that is my choice, not a hard to change behavior.

The built in primitives in FreeMarker is also great, e.g. <#assign> that allows me to store any generated output in a variable for later usage.

${pojo.getPackageDeclaration()}
// Generated ${date} by Hibernate Tools ${version}
<#assign classbody>
 <#include "PojoTypeDeclaration.ftl"/> {
  ..more template code..
 }
</#assign>

${pojo.generateImports()}
${classbody}

This allows me to remove the need to have a magically second-pass which I did with Velocity. There are more gems like these to be found in the excellent FreeMarker documentation .

Another big plus in FreeMarker's favor is the Configuration API . Let us compare, here is our Velocity setup:

engine = new VelocityEngine();
context = new VelocityContext();

EventCartridge ec = new EventCartridge();
ec.addEventHandler(new HibernateEventHandler()); // stricter evaluation
ec.attachToContext( context );
            
Properties p = new Properties();
p.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, 
              "org.apache.velocity.tools.generic.log.CommonsLogLogSystem");
p.setProperty(CommonsLogLogSystem.LOGSYSTEM_COMMONS_LOG_NAME, 
              "org.hibernate.tool.hbm2x.template");

p.setProperty( RuntimeConstants.UBERSPECT_CLASSNAME, HibernateUberspect.class.getName() ); // stricter evaluation

p.setProperty("velocimacro.library",""); // make it shut up about VM_global_library blah
      
p.setProperty("resource.loader", "file, class");
p.setProperty("file.resource.loader.path", directory );
p.setProperty("class.resource.loader.class", ClasspathResourceLoader.class.getName() );

engine.init(p);

Here is the corresponding FreeMarker config:

engine = new Configuration();
context = new SimpleHash(ObjectWrapper.BEANS_WRAPPER);

//Logger.setCategoryPrefix("org.hibernate.tool.hbm2x.template"); 
// Not really needed since the logging is much more sensible.

freeMarkerEngine.setTemplateLoader(new MultiTemplateLoader( 
                                    new FileTemplateLoader(directory), 
                                    new ClassTemplateLoader(this.getClass(),"/"));

Notice the difference? FreeMarker has good practice defaults and actually allows me to use java code to configure it; what a neat concept.

The only two bad things I have found yet with FreeMarker is that itís syntax is based on <#..> which does not compute very well when trying to show it in an XML editor. This has been fixed in the latest release by also allowing [#...] syntax.

Another bigger issue is that ${} and #{} is not escapable. This syntax collides in templates that generates ant build and jsp files.

In Velocity they were just ignored (the only place were it were useful to ignore them). FreeMarker complains because the values are undefined and unfortunately there is no easy-on-the-eyes method to escape these characters. The following show the methods that I found to allow the me to output ${..}:

${r"${build.dir}"}  
${'$í}{build.dir} 
<#noescape>${build.dir}</noescape>

Still the brilliant exception handling, powerful template language and configuration API makes FreeMarker a much better choice for Hibernate Tools.

What now ?

Velocity served me well and is probably serving many projects well; it just did not cut it well for Hibernate Tools. Today I am convinced that I could have saved myself and the Hibernate world from a lot of trouble if I had decided to use FreeMarker from the beginning.

Come and see for your self in the TOOLS_FREEMARKER branch. The code in there will be merged into the main development in the near future unless someone steps up with a very good reason for not doing so ;)

To be fair, I must tell you that Velocity 1.5 is being worked on right now, and it does seem to solve some of these issues, but not completely and Velocity has some external dependencies I would rather not add to the tools project.

back to top