Problem with Manning Hibernate example about annotated collections of embeddable elements
Posted by admin on February 24th, 2009 filed in TipsIf you are following the example in the book on page 259, and using Spring 2.5.6 and Hibernate 3.3.0.ga, you may get an error like:
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘txSessionFactory’ defined in ServletContext resource [/WEB-INF/mymodule-dao.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: Could not determine type for: java.util.Set, for columns: [org.hibernate.mapping.Column(Image)]
The example in the book shows that the annotations should be set on the private field, but they should actually be set on the public getter.
@org.hibernate.annotations.CollectionOfElements
@JoinTable(
name = "ITEM_IMAGE",
joinColumns = @JoinColumn(name = "ITEM_ID")
)
private Set<Image> images = new HashSet<Image>();
should be:
@org.hibernate.annotations.CollectionOfElements
@JoinTable(
name = "ITEM_IMAGE",
joinColumns = @JoinColumn(name = "ITEM_ID")
)
public Set<Image> getImages() {
return images;
}
This may be due to the added layer of the interaction with Spring. Either way, give it a shot if you are experiencing this problem.
September 16th, 2009 at 6:55 pm
Thank you so much. You saved so much time to me.