Hi,
I'm evaluating SmartGWTEE 2.4 at the moment and I have a question concerning the JPA datasource handling.
I have a tree mapping using the @OneToMany and @ManyToOne annotations.
The entity class could look something like that:
The datasource
Now, if I want to create a new Treenode resp. Record on the client I only have the IDs of my entities available.
So if I do something like that:
I get the obvious error "Can't convert value of type java.lang.Long to target type com.sample.server.MyTreeNode"
Here's what the request looks like:
Am I missing something here? Or do I have to use DMI and set the Parent entity manually?
Thanks in advance.
I'm evaluating SmartGWTEE 2.4 at the moment and I have a question concerning the JPA datasource handling.
I have a tree mapping using the @OneToMany and @ManyToOne annotations.
The entity class could look something like that:
Code:
@Entity public class MyTreeNode implements Serializable { private Long id; private String name; private MyTreeNode parent; private List<MyTreeNode> children; @Id @GeneratedValue public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } @ManyToOne public MyTreeNode getParent() { return parent; } public void setParent(MyTreeNode parent) { this.parent = parent; } @OneToMany(cascade = CascadeType.ALL) public List<MyTreeNode> getChildren() { return children; } public void setChildren(List<MyTreeNode> children) { this.children = children; } }
Code:
<DataSource ID="tree_DS" serverConstructor="com.isomorphic.jpa.JPADataSource" beanClassName="com.sample.server.MyTreeNode"> <fields> <field name="id" type="integer" hidden="true" primaryKey="true"/> <field name="name" type="text" title="Name" required="true"/> <field name="parent" type="integer" foreignKey="tree_DS.id"/> </fields> </DataSource>
So if I do something like that:
Code:
button.addClickHandler(new ClickHandler() { public void onClick(ClickEvent clickEvent) { com.smartgwt.client.widgets.tree.TreeNode selectedRecord = (com.smartgwt.client.widgets.tree.TreeNode) treeGrid.getSelectedRecord(); String parentId = selectedRecord == null ? "" : selectedRecord.getAttribute("id"); com.smartgwt.client.widgets.tree.TreeNode node = new com.smartgwt.client.widgets.tree.TreeNode(); node.setAttribute("name", "SampleName"); node.setAttribute("parent", parentId); treeGrid.addData(node); } });
Here's what the request looks like:
Code:
{ values:{ name:"SampleName", parent:"1" }, operationConfig:{ dataSource:"tree_DS", operationType:"add" }, componentId:"isc_TreeGrid_0", appID:"builtinApplication", operation:"tree_DS_add", oldValues:{ name:"SampleName", parent:"1" }, criteria:{ } }
Thanks in advance.
Comment