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:
Roo will then delete the ID definition from the aspect file and use your definition and update your controllers, etc.Code:@Id @GeneratedValue(generator="system-uuid") @GenericGenerator(name="system-uuid", strategy = "uuid2") @Column(name = "id") @Type(type="pg-uuid") private UUID id; public UUID getId() { return this.id; } public void setId(UUID id) { this.id = id; }
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:
Then update your webmvc-config.xml to include the converters:Code:public class StringToUUIDConverter implements Converter<String, UUID> { @Override public UUID convert(String source) { return UUID.fromString(source); } } public class UUIDToStringConverter implements Converter<UUID, String> { @Override public String convert(UUID source) { return source.toString(); } }
And that should do it.Code:<mvc:annotation-driven conversion-service="conversionService"/> <bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean"> <property name="converters"> <list> <bean class="com.foobar.StringToUUIDConverter" /> <bean class="com.foobar.UUIDToStringConverter" /> </list> </property> </bean>


Reply With Quote