Announcement Announcement Module
No announcement yet.
Working: Postgres UUID ID fields Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Working: Postgres UUID ID fields

    I was able to get Postgres UUID ID fields working with Roo 1.1M3, in case anyone is interested. This only works with Spring MVC, as the GWT scaffold currently requires Long IDs (a limitation of GWT's Record interface).

    First, you'll need the latest beta of Hibernate (3.6beta4 as of this writing). This adds java.util.UUID support.

    In your entity class, add something like the following for your ID field:
        @GenericGenerator(name="system-uuid", strategy = "uuid2")
        @Column(name = "id")
        private UUID id;
        public UUID getId() {
        public void setId(UUID id) {
   = id;
    Roo will then delete the ID definition from the aspect file and use your definition and update your controllers, etc.

    You will also need to add String <-> UUID converters to Spring MVC. This allows Spring's IdToEntityConverter to work correctly with UUID IDs. Create two converters, something like these:

    public class StringToUUIDConverter implements Converter<String, UUID> {
        public UUID convert(String source) {
            return UUID.fromString(source);
    public class UUIDToStringConverter implements Converter<UUID, String> {
        public String convert(UUID source) {
            return source.toString();
    Then update your webmvc-config.xml to include the converters:

    <mvc:annotation-driven conversion-service="conversionService"/>
    <bean id="conversionService" class="">
        <property name="converters">
                <bean class="com.foobar.StringToUUIDConverter" />
                <bean class="com.foobar.UUIDToStringConverter" />
    And that should do it.

  • #2
    I just found, which makes me surprised you needed to write a converter. You might like to log a bug against Roo at (and reference this forum thread) just so Stefan can take a quick look at this when he gets back from holidays. If UUID support doesn't work out-of-the-box with Spring Framework, we should revisit the intent of SPR-6696 and open a Spring Framework ticket accordingly.

    I'm pleased you got it working in the meantime, and thanks for sharing your approach. My suggestion above is just aimed at eliminating the need for Roo users to need to go to the trouble of writing a converter.



    • #3
      I think that the bug you referenced doesn't affect this. The resolution to that bug was to add a UUID property editor. The problem I faced was with the IdToEntityConverter class, which uses the conversion service to convert a string to an identifier. Without the UUID converters, the IdToEntityConverter class cannot figure out how to call the appropriate finder method to retrieve the entity.