Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Recursive Mapping of collections

 
Echo.Narcissus Echo
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://docs.jboss.org/hibernate/core/3.3/reference/en/html/collections.html... really has me befuddled.

I am trying to create a ToDo List with Vaadin/ Hibernate /Spring /MySQL.

So my <hibernate mapping> looks like this


And my Task.java thus



I am expecting that each Task in the Task table will have an entry ParentId which in relation to TaskId (indexed key of the table) will give the one-to-many parent to child collection mapping.

Obviously it seems that this mapping is not something i understood very well.
Because hibernate complains ..

nested exception is org.hibernate.MappingException: Repeated column in mapping for entity: com.intellizens.ribbon.tasks.model.Task column: parentId (should be mapped with insert="false" update="false")

Or is it that i am expecting hibernate to read my mind.. and making a obvious mistake.
 
Waswani Naresh
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Echo,

You are probably trying to do some thing like....

One task can have multiple sub-tasks and each task will have its parent task ID.

Try this approach


Task.java


Task.hbm.xml


Do let me know if this serves the purpose.

Regards,
Naresh Waswani
 
Echo.Narcissus Echo
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your response.

What about the parentId mapping?

<property name="parentId" type="java.lang.Long">
<column name="parentId" length="45" not-null="true" />
</property>
 
Waswani Naresh
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at the key element with in the set. Its mapped to PARENT_ID. So you don't need to define it separately.

Regards,
Naresh Waswani
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic