This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

AnnouncementAnnouncement Module

Collapse

No announcement yet.

MongoDB - Multiple constructors found for @Transient annotated field in @Document entPage Title Module

MongoDB - Multiple constructors found for @Transient annotated field in @Document ent

Sep 22nd, 2011, 09:28 AM

Hi

I'm getting an error trying to use the java.util.UUID class within my @Document entity. I have read this post http://forum.springsource.org/showth...ngoDB-1.0.0.M2, which seems to solve the issue, but I cannot seem to get it implemented. I have the following settings:
The xml setup of the mongo stuff:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'metadataMongoRepository': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: Multiple constructors with arguments found in class java.util.UUID! Annotate one with @PersistenceConstructor explicitly to select it to be used in persistence operations.

If I remove the UUID I can start the application fine. Does anybody have a hint to what I'm doing wrong ?

UUID is not a native MongoDB type, thus we treat it like an entity by default unless you register a custom converter for it (see [0] for details). Feel free to open a ticket for including it by default.

Comment

What version of SD MongoDB are you using? We did some significant overhaul of the converter handling for M4 and the config you showed should work actually. Actually it should be enough to rather simply implement a UuidToStringConverter or StringToUuidConverter respectively.

Comment

But it has totally been my fault. By mistake I blindly let eclipse import the javax.persistence.Transient annotation instead of the org.springframework.data.annotation.Transient annotation. Changing this import makes things work fine.

Sorry and thanks for your patience and responses, I'll remember to copy imports next time I have any issues ;-)