Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 3.2.5.ga
Name and version of the database you are using:MySQL 5.0.18
Hello All,
I am new to hibernate so please excuse any broach in protocol. I have a uni-directional List of objects that I have mapped as one to many (mapping code to follow)
Code:
@OneToMany(cascade = CascadeType.ALL)
@Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
@JoinTable(name = "WIDGET_CONTAINER_WIDGETS", joinColumns = {@JoinColumn(name = "WIDGET_CONTAINER_ID", nullable = false)}, inverseJoinColumns = @JoinColumn(name = "WIDGET_ID", nullable = false))
@org.hibernate.annotations.IndexColumn(name = "WIDGET_POSITION")
My test executes the following code:
Code:
final Transaction tx = session.beginTransaction();
final WidgetContainer theContainer = (WidgetContainer)session.get(WidgetContainer.class, containerId);
assertNotNull(theContainer);
final Widget widget2 = theContainer.getWidgets().get(1);
final List<Widget> widgetList = theContainer.getWidgets();
// remove the widget from the list
widgetList.remove(widget2);
// delete the widget from the persistence model
session.delete(widget2);
session.saveOrUpdate(theContainer);
tx.commit();
I am getting the following exception when I attempt to remove an item from the list:
Code:
java.lang.UnsupportedOperationException
at java.util.AbstractList.remove(AbstractList.java:172)
at org.hibernate.collection.PersistentList.remove(PersistentList.java:319)
I am certain that there is user error involved here, but after searching the forums and Google all day I haven't gotten any lead on what I might be doing wrong.
If anyone can offer any advice or insight either into my issue specifically or mapping Lists that I might have missed I would appreciate it.
Thank you for your help,
Dave