Re: How do you update a record with apache cayenne without using select clause
> On Sep 11, 2015, at 6:32 PM, Dipesh Jainwrote: > > I am using apache cayenne 3.1. I know of one way to update records in the > database is to first use select query to find record and then update it, > but I don't want to use a select query for updating. How can I directly > update the record? I do not want to use EJBQLQuery or SQL TEMPLETE. > > -- > Thanks and Regards > Deepesh Jain Hi Deepesh, My #1 solution won't be EJBQLQuery or SQLTemplate either. I would actually select the objects that I need, change them and commit. This is a true ORM solution, as you are working with objects, can apply business logic, listeners and what not. In more rare cases of "bulk update", when a single query updates a bunch of records without bothering to fault objects, EJBQLQuery or SQLTemplate is the way to do it. So what case are you dealing with? Andrus
Re: Anyone using Cayenne with Informix?
Thanks Andrus. I’m going to try this out. - hugi > On 11. sep. 2015, at 10:34, Andrus Adamchikwrote: > > Haven't seen anything Informix-related popping up on this list for some time. > But if it has a decent JDBC driver, most things should just work. Most > adapter customizations for other DBs are dealing with edge cases, stored > procedures, driver metadata capabilities and such. > > Andrus > >> On Sep 11, 2015, at 1:24 PM, Hugi Thordarson wrote: >> >> Hi all. >> >> I’m starting work on a (somewhat technologically dated) project that uses >> Informix. I see it’s not on the list of officially supported DBs, just >> wondering if anyone has attempted to use it with Cayenne? >> >> - hugi >
Re: Switching to Java 1.7
Awesome :) - hugi > On 11. sep. 2015, at 10:33, Andrus Adamchikwrote: > > FYI. Feel free to comment. > >> Begin forwarded message: >> >> From: Andrus Adamchik >> Subject: Switching to Java 1.7 >> Date: September 7, 2015 at 10:13:46 AM GMT+3 >> To: d...@cayenne.apache.org >> Reply-To: d...@cayenne.apache.org >> >> So one final reminder that we are establishing lazy consensus for switching >> Cayenne 4.0 to Java 1.7. I think may still wait a few more days, and then do >> it. To summarize past threads on the topic, the only concern is that there >> is a correlation between container JEE version and supported version of >> J2SE, so some JEE 1.6 containers may require Java 6. >> >> Andrus >
Fwd: Switching to Java 1.7
FYI. Feel free to comment. > Begin forwarded message: > > From: Andrus Adamchik> Subject: Switching to Java 1.7 > Date: September 7, 2015 at 10:13:46 AM GMT+3 > To: d...@cayenne.apache.org > Reply-To: d...@cayenne.apache.org > > So one final reminder that we are establishing lazy consensus for switching > Cayenne 4.0 to Java 1.7. I think may still wait a few more days, and then do > it. To summarize past threads on the topic, the only concern is that there is > a correlation between container JEE version and supported version of J2SE, so > some JEE 1.6 containers may require Java 6. > > Andrus
Anyone using Cayenne with Informix?
Hi all. I’m starting work on a (somewhat technologically dated) project that uses Informix. I see it’s not on the list of officially supported DBs, just wondering if anyone has attempted to use it with Cayenne? - hugi
Re: Anyone using Cayenne with Informix?
Haven't seen anything Informix-related popping up on this list for some time. But if it has a decent JDBC driver, most things should just work. Most adapter customizations for other DBs are dealing with edge cases, stored procedures, driver metadata capabilities and such. Andrus > On Sep 11, 2015, at 1:24 PM, Hugi Thordarsonwrote: > > Hi all. > > I’m starting work on a (somewhat technologically dated) project that uses > Informix. I see it’s not on the list of officially supported DBs, just > wondering if anyone has attempted to use it with Cayenne? > > - hugi
Re: Query at the time of inserting data using Apache Cayenne
I have tried to implement @Aristedes Maniatis answer but still result was same. I want to know why and how apache cayenne is doing this. I do not want the solution because I already have the answer. On Wed, Sep 9, 2015 at 9:41 PM, Dipesh Jainwrote: > I have written a code in java 8 to insert data in sql server 2012 using > apache cayenne 3.1. While executing code I got an exception : > **org.apache.cayenne.CayenneRuntimeException: [v.3.1 Sep 20 2014 14:24:57] > Commit Exception Caused by: java.sql.SQLException: Could not find stored > procedure 'auto_pk_for_table'**. > > I have solved the problem by changing my pk generation strategy in cayenne > modeler from default to database generated. But when I executed my java > code again, it was suppose to insert only 1 record in database but it also > inserted previous record which I got in exception. I have tried creating > the same scenario thrice but I got the same result. I also tried restarting > my web server and SQL server service after getting an exception, but at the > time of inserting new data exceptional record was also been inserted at the > same time. > This Problem is also solved by inserting a rollback statement in my catch > block. > > But I want to know that how and why is apache cayenne inserting > exceptional data at the time of inserting new data. > > This is my code. > **Java :** > PersonDao > > try { > Person person = new Person(); > person.setFirstName("John"); > person.setLastName("Cross"); > ObjectContext context = BaseContext.getThreadObjectContext(); > context.registerNewObject(person); > context.commitChanges(); > } catch (CayenneRuntimeException e) { > context.rollbackChanges(); > throw e; > } > > **XML files :** > cayenne-test.xml > > > > value="true"/> > > factory="org.apache.cayenne.configuration.server.XMLPoolingDataSourceFactory" > schema-update-strategy="org.apache.cayenne.access.dbsync.CreateIfNoSchemaStrategy"> > > > > > > > > > > > TestDataMap.map.xml > > > http://cayenne.apache.org/schema/3.0/modelMap; > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance; > xsi:schemaLocation="http://cayenne.apache.org/schema/3.0/modelMap > http://cayenne.apache.org/schema/3.0/modelMap.xsd; > project-version="6"> > > > isGenerated="true" isMandatory="true" length="10"/> > > > > className="com.org.ivcargo.platform.dto.PersonTemp" > dbEntityName="PersonTemp"> > db-attribute-path="personId"/> > db-attribute-path="firstname"/> > db-attribute-path="lastname"/> > > > > -- > Thanks and Regards > Deepesh Jain > -- Thanks and Regards Deepesh Jain
How do you update a record with apache cayenne without using select clause
I am using apache cayenne 3.1. I know of one way to update records in the database is to first use select query to find record and then update it, but I don't want to use a select query for updating. How can I directly update the record? I do not want to use EJBQLQuery or SQL TEMPLETE. -- Thanks and Regards Deepesh Jain
Re: How do you update a record with apache cayenne without using select clause
On 12/09/2015 1:32am, Dipesh Jain wrote: > I am using apache cayenne 3.1. I know of one way to update records in the > database is to first use select query to find record and then update it, > but I don't want to use a select query for updating. How can I directly > update the record? I do not want to use EJBQLQuery or SQL TEMPLETE. That's a bit like asking "how do I code in Java without using a keyboard?" What are you trying to do and why are you trying to do it without the tools the ORM gives you? Ari -- --> Aristedes Maniatis GPG fingerprint CBFB 84B4 738D 4E87 5E5C 5EFA EF6A 7D2E 3E49 102A
Re: Query at the time of inserting data using Apache Cayenne
Ari's example was idiomatic Cayenne, even though it did not contain the solution. I.e. it is generally a good idea to create and register a new object in one place with context.newObject(..), before you start modifying object properties. Anyways... >> I have solved the problem by changing my pk generation strategy in cayenne >> modeler from default to database generated. Yep, that's a good approach to PK generation in SQLServer. >> But when I executed my java >> code again, it was suppose to insert only 1 record in database but it also >> inserted previous record which I got in exception. When you inserted the second record into ObjectContext, the context was already "dirty", i.e. contained changes from somewhere else. My guess is you are reusing the same ObjectContext across multiple web requests. You are probably using CayenneFilter to bootstrap Cayenne, which provides session-scoped context by default. There are different ways to solve it. Here is one - you can switch to request-scoped context (if you don't need to preserve uncommitted changes across requests): # Create a custom module overriding RequestHandler # to use org.apache.cayenne.configuration.web.StatelessContextRequestHandler package com.foo; ... public class MyModule implements Module { @Override public void configure(Binder binder) { binder.bind(RequestHandler.class) .to(StatelessContextRequestHandler.class) .withoutScope(); } } # load it in CayenneFilter in web.xml: cayenne-project org.apache.cayenne.configuration.web.CayenneFilter extra-modules com.foo.MyModule Hope this helps. Andrus > On Sep 11, 2015, at 5:16 PM, Dipesh Jainwrote: > > I have tried to implement @Aristedes Maniatis answer but still result was > same. I want to know why and how apache cayenne is doing this. I do not > want the solution because I already have the answer. > > On Wed, Sep 9, 2015 at 9:41 PM, Dipesh Jain wrote: > >> I have written a code in java 8 to insert data in sql server 2012 using >> apache cayenne 3.1. While executing code I got an exception : >> **org.apache.cayenne.CayenneRuntimeException: [v.3.1 Sep 20 2014 14:24:57] >> Commit Exception Caused by: java.sql.SQLException: Could not find stored >> procedure 'auto_pk_for_table'**. >> >> I have solved the problem by changing my pk generation strategy in cayenne >> modeler from default to database generated. But when I executed my java >> code again, it was suppose to insert only 1 record in database but it also >> inserted previous record which I got in exception. I have tried creating >> the same scenario thrice but I got the same result. I also tried restarting >> my web server and SQL server service after getting an exception, but at the >> time of inserting new data exceptional record was also been inserted at the >> same time. >> This Problem is also solved by inserting a rollback statement in my catch >> block. >> >> But I want to know that how and why is apache cayenne inserting >> exceptional data at the time of inserting new data. >> >> This is my code. >> **Java :** >> PersonDao >> >>try { >>Person person = new Person(); >>person.setFirstName("John"); >>person.setLastName("Cross"); >>ObjectContext context = BaseContext.getThreadObjectContext(); >>context.registerNewObject(person); >>context.commitChanges(); >>} catch (CayenneRuntimeException e) { >>context.rollbackChanges(); >>throw e; >>} >> >> **XML files :** >> cayenne-test.xml >> >> >> >>> value="true"/> >> >>> factory="org.apache.cayenne.configuration.server.XMLPoolingDataSourceFactory" >> schema-update-strategy="org.apache.cayenne.access.dbsync.CreateIfNoSchemaStrategy"> >> >> >> >> >> >> >> >> >> >> >> TestDataMap.map.xml >> >> >>http://cayenne.apache.org/schema/3.0/modelMap; >> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance; >> xsi:schemaLocation="http://cayenne.apache.org/schema/3.0/modelMap >> http://cayenne.apache.org/schema/3.0/modelMap.xsd; >> project-version="6"> >> >> >> > isGenerated="true" isMandatory="true" length="10"/> >> >> >> >> > className="com.org.ivcargo.platform.dto.PersonTemp" >> dbEntityName="PersonTemp"> >> > db-attribute-path="personId"/> >> > db-attribute-path="firstname"/> >> > db-attribute-path="lastname"/> >> >> >> >> -- >> Thanks and Regards >> Deepesh Jain >> > > > > -- > Thanks and Regards > Deepesh Jain