I have a problem populating a detail view from the database.
application.xml snippet:
<module name="ModuleB">
<model name="B"/>
<view name="ViewB"/>
...
<mode-controller name="DetailOnly"/>
</module>
I have three entity classes:
@Entity
@Table(name="A")
class A {
@OneToMany(mappedBy = "a")
@ListProperties("col1")
@CollectionView("cs")
private Collection<C> cs;//+getter/setters
}
@Entity
@Table(name="A")
@View(name = "ViewB", ...)
class B {
@OneToMany(mappedBy = "a")
@ListProperties(...)
@CollectionView("ViewC")
private Collection<C> cs;//+getter/setters
}
@Entity
@Table(name="C")
@View(name = "ViewC", ...)
class C {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "a_id")
private A a;
}
I want to read an existing B instance from the database by clicking on a link, then editing/modify it. When I set the model object of the view with getView().setModel() or even using getView().findObject(), on the screen everything looks good, the collection shows its proper content. On the other hand when i try to save it back, in the save action the getView().getEntity().getCs() collection is null. What do I have to do to make the view being correspond to the entity behind?
I am using OpenXava 5.0.1, java 1.7 Important note: I am not allowed to change OpenXava version, since it is a legacy project.
My editing (20170126) I've made a new class to avoid a reference problem:
@Entity
@Table(name="C")
@View(name = "ViewC", ...)
class D {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "a_id")
private B a;
}
and modified the class B accordingly:
@Entity
@Table(name="A")
@View(name = "ViewB", ...)
class B {
@OneToMany(mappedBy = "a")
@ListProperties(...)
@CollectionView("ViewC")
private Collection<D> cs;//+getter/setters
}
But the result is the same: The records of the subview (Collection ViewC) are loaded from the DB, and shown on the screen correctly, but I get an error message if I want to edit the Collection ViewC ( eg: add a new entry ): "Impossible to execute Save action: Impossible to create: an object with that key already exists" + As before: in the save action the getView().getEntity().getCs() collection is null