Hi Michael,
Thanks for the quick response..based on your given code..this is what i did
with Click and Cayenne..luckily Click have a PropertySelect that supports
Cayenne to-one relationship..so what im trying to test now is the
to-many..the only option ive got is to do it manually...can you take a quick
look with my short code to see what im missing..ive got a SQLException
error, Duplicate Entry..it seems like Cayenne save a new instance of
Categories which i dont intend to...thanks in advance.and hey im looking
forward for a Cayenne Books..hope you guys release one..im willing to buy
one..
*******CODES***************************
public class ManageProducts extends BorderPage {
public CayenneForm form = new CayenneForm("form",Products.class);
private QuerySelect query;
public ManageProducts(){
form.add(new TextField("name"));
form.add(new TextField("serial"));
query = new QuerySelect("categories.name");
query.setQueryValueLabel("FindCategories", "name", "name");
form.add(query);
form.add(new Submit("save"," Save ",this,"onSaveClick"));
}
public boolean onSaveClick(){
if(form.isValid()){
Categories category = getCategoryService().findCategoryByName(
query.getValue());
Products products = (Products) form.getDataObject();
products.setCategories(category);
if(category != null){
getDataContext().commitChanges();
form.clearValues();
return true;
} else {
return false;
}
} else {
return false;
}
}
}
************ERRORS******************************
[Click] [debug] Form -> Products.name : preofdkjfk
[Click] [debug] Form -> Products.serial : 122837
[Click] [debug] Form -> Products.categories.name : Category 2
[Click] [error] handleException:
org.objectstyle.cayenne.CayenneRuntimeException: [v.1.2.1 September 19 2006]
Commit Exception
at org.objectstyle.cayenne.access.DataContext.flushToParent(
DataContext.java:1289)
at org.objectstyle.cayenne.access.DataContext.commitChanges(
DataContext.java:1165)
at org.russagri.page.inventory.ManageProducts.onSaveClick(
ManageProducts.java:40)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.sf.click.util.ClickUtils.invokeListener(ClickUtils.java:881)
at net.sf.click.control.Field.invokeListener(Field.java:1097)
at net.sf.click.control.Submit.onProcess(Submit.java:207)
at net.sf.click.control.Form.onProcess(Form.java:1833)
at net.sf.click.extras.cayenne.CayenneForm.onProcess(CayenneForm.java
:467)
at net.sf.click.ClickServlet.processPage(ClickServlet.java:484)
at net.sf.click.ClickServlet.handleRequest(ClickServlet.java:357)
at net.sf.click.ClickServlet.doPost(ClickServlet.java:302)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(
ApplicationFilterChain.java:173)
at net.sf.click.extras.filter.CompressionFilter.doFilter(
CompressionFilter.java:209)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(
ApplicationFilterChain.java:173)
at net.sf.click.extras.cayenne.DataContextFilter.doFilter(
DataContextFilter.java:125)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(
ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(
StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(
StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(
StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(
ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(
StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(
CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:869)
at
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection
(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(
PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(
LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(
ThreadPool.java:684)
at java.lang.Thread.run(Unknown Source)
Caused by: java.sql.SQLException: Duplicate entry 'Category 2' for key 2
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2975)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1600)
at com.mysql.jdbc.ServerPreparedStatement.serverExecute(
ServerPreparedStatement.java:1125)
at com.mysql.jdbc.ServerPreparedStatement.executeInternal(
ServerPreparedStatement.java:677)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java
:1357)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java
:1274)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java
:1259)
at
org.objectstyle.cayenne.access.jdbc.BatchAction.runAsIndividualQueries(
BatchAction.java:224)
at org.objectstyle.cayenne.access.jdbc.BatchAction.performAction(
BatchAction.java:117)
at org.objectstyle.cayenne.access.DataNodeQueryAction.runQuery(
DataNodeQueryAction.java:95)
at org.objectstyle.cayenne.access.DataNode.performQueries(DataNode.java
:309)
at org.objectstyle.cayenne.access.DataDomainFlushAction.runQueries(
DataDomainFlushAction.java:255)
at org.objectstyle.cayenne.access.DataDomainFlushAction.flush(
DataDomainFlushAction.java:177)
at org.objectstyle.cayenne.access.DataDomain.onSyncFlush(DataDomain.java
:830)
at org.objectstyle.cayenne.access.DataDomain$2.transform(DataDomain.java
:801)
at org.objectstyle.cayenne.access.DataDomain.runInTransaction(
DataDomain.java:856)
at org.objectstyle.cayenne.access.DataDomain.onSync(DataDomain.java:798)
at org.objectstyle.cayenne.access.DataContext.flushToParent(
DataContext.java:1261)
... 36 more
[Click] [info ] renderTemplate: /click/error.htm - 15 ms
[Click] [info ] handleRequest: /inventory/manage-products.htm - 1047 ms
[Click] [debug] Uncommitted data objects:
[Click] [debug] {<ObjectId:Categories, TEMP:0000017ADC440001>; new;
[products=>(..); name=>Category 2]}
[Click] [debug] {<ObjectId:Products, TEMP:0000007ADC060001>; new;
[categories=>{<ObjectId:Categories, id=201>}; name=>preofdkjfk;
serial=>122837]}
On 1/20/07, Michael Gentry <blacknex..mail.com> wrote:
>
> When you model the relationships in Cayenne Modeler and then generate
> the Java classes, it'll create set* methods and addTo* methods for
> your relationships.
>
> So in your case, something similar to this should work:
>
> Category category = [code to get your Category object];
> Product product = dataContext.createAndRegisterNewObject(Product.class);
> product.setCategory(category);
> ...
>
> /dev/mrg
>
>
> On 1/20/07, Jun Bondoy <dvbondo..mail.com> wrote:
> > Hi list,
> >
> > can somebody help me please. i have a products object with to-one
> > relationship with my categories object. what i want to do is create a
> new
> > products and use an existing categories object. below are the steps i
> did...
> >
> > 1. lookup for my existing categories via query
> > 2. create a new product object
> >
> > how can i set the product object on the categories object before i
> commit?
> >
> > thanks in advance..
> >
> > Best Regards
> > -jun
> >
> >
>
This archive was generated by hypermail 2.0.0 : Sun Jan 21 2007 - 01:18:27 EST