Hello,
We are curently investigating the implementation of a complete solution based on SmartGWT framework. In order to do so we have installed SmartGWTee 2.5 and GWT 2.3. We are using Firefox 3.6.12 as browser.
So far, we are quite happy about the possibilities of smartGWT, but we are facing difficulties with foreign keys and JPA.
We have implemented Many to One relation base on the sample provide by this link: http://www.smartclient.com/smartgwtee/showcase/#jpaRelationManyToOneSimple
We tried to filter the ListGrid with a criteria on the foreign key where we select only the invoices with the applicant id 1, but it doesn't work:
We have warning in the logs:
=== 2011-10-05 10:40:30,832 [l0-5] WARN JPA2DataSource - [builtinApplication.invoice_fetch] Failed to cast value for field 'applicant'.
Value '1' of type 'class java.lang.Long' can not be casted to type 'class dataModel.Applicant'.
Skipping.
We also tried to change the criterio to match the valueXPath:
and we have the following warning:
=== 2011-10-05 10:45:08,724 [l0-2] WARN JPA2DataSource - [builtinApplication.invoice_fetch] Failed to identify path for field 'applicant.id'.
java.lang.NullPointerException
at org.hibernate.ejb.criteria.path.AbstractPathImpl.unknownAttribute(AbstractPathImpl.java:110)
at org.hibernate.ejb.criteria.path.AbstractPathImpl.locateAttribute(AbstractPathImpl.java:218)
at org.hibernate.ejb.criteria.path.AbstractPathImpl.get(AbstractPathImpl.java:189)
at com.isomorphic.jpa.JPA2DataSource.getPropertyPath(JPA2DataSource.java:1978)
...
In two words, an applicant has many invoices and an invoices belongs to one and only one applicant, so the JPA definition of the list to be displayed is:
And the JPA definition for the applicant:
The data source definition are the following:
and:
Thank you in advance for your help.
Kind regards,
Samuel Boclinville
We are curently investigating the implementation of a complete solution based on SmartGWT framework. In order to do so we have installed SmartGWTee 2.5 and GWT 2.3. We are using Firefox 3.6.12 as browser.
So far, we are quite happy about the possibilities of smartGWT, but we are facing difficulties with foreign keys and JPA.
We have implemented Many to One relation base on the sample provide by this link: http://www.smartclient.com/smartgwtee/showcase/#jpaRelationManyToOneSimple
We tried to filter the ListGrid with a criteria on the foreign key where we select only the invoices with the applicant id 1, but it doesn't work:
Code:
ListGrid listgrid= new ListGrid(); listgrid.setDataSource(DataSource.get("invoice")); Criteria criteria = new Criteria(); criteria.addCriteria("applicant",1); listgrid.fetchData(criteria);
=== 2011-10-05 10:40:30,832 [l0-5] WARN JPA2DataSource - [builtinApplication.invoice_fetch] Failed to cast value for field 'applicant'.
Value '1' of type 'class java.lang.Long' can not be casted to type 'class dataModel.Applicant'.
Skipping.
We also tried to change the criterio to match the valueXPath:
Code:
criteria.addCriteria("applicantid",1);
=== 2011-10-05 10:45:08,724 [l0-2] WARN JPA2DataSource - [builtinApplication.invoice_fetch] Failed to identify path for field 'applicant.id'.
java.lang.NullPointerException
at org.hibernate.ejb.criteria.path.AbstractPathImpl.unknownAttribute(AbstractPathImpl.java:110)
at org.hibernate.ejb.criteria.path.AbstractPathImpl.locateAttribute(AbstractPathImpl.java:218)
at org.hibernate.ejb.criteria.path.AbstractPathImpl.get(AbstractPathImpl.java:189)
at com.isomorphic.jpa.JPA2DataSource.getPropertyPath(JPA2DataSource.java:1978)
...
In two words, an applicant has many invoices and an invoices belongs to one and only one applicant, so the JPA definition of the list to be displayed is:
Code:
@Entity @Table(name = "T_INVOICE") @Audited public class Invoice{ @Id @Column (nullable = false) @GeneratedValue(strategy = GenerationType.TABLE) private long id; @ManyToOne @JoinColumn(name="applicant", referencedColumnName="id") private Applicant applicant; @Basic private String invoiceNumber; }
Code:
@Entity @Table(name = "T_APPLICANT") @Audited public class Applicant { @Id @Column (nullable = false) @GeneratedValue(strategy = GenerationType.TABLE) private long id; @OneToMany(mappedBy="applicant") private List<Invoice> invoices = new ArrayList<Invoice>(); @Basic private String name; }
Code:
<DataSource ID="invoice" serverConstructor="com.isomorphic.jpa.JPA2DataSource" beanClassName="dataModel.Invoice" schemaBean="dataModel.Invoice"> <fields> <field name="applicantid" type="number" valueXPath="applicant/id" /> <field name="applicant" title="Applicant" displayField="name" foreignKey="applicant.id" /> <field name="invoiceNumber" type="text" title="Invoice Number" required="true" /> </fields> </DataSource>
Code:
<DataSource ID="applicant" serverConstructor="com.isomorphic.jpa.JPA2DataSource" beanClassName="dataModel.Applicant" schemaBean="dataModel.Applicant"> <fields> <field primaryKey="true" name="id" hidden="true" type="sequence" /> <field name="name" title="Applicant Name" type="text" /> </fields> </DataSource>
Kind regards,
Samuel Boclinville
Comment