cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John Huss <johnth...@gmail.com>
Subject Re: Query at the time of inserting data using Apache Cayenne
Date Sat, 12 Sep 2015 12:52:37 GMT
You can just copy StatelessContextRequestHandler. It's small and simple.
On Sat, Sep 12, 2015 at 7:48 AM Dipesh Jain <dipesh@ivgroup.in> wrote:

> Thanks @Andrus for the help. I am using CayenneFilter session-scoped
> context,
> because of that I was having problem. I saw your solution but I am using
> cayenne 3.1 and it does not have StatelessContextRequestHandler class. My
> entire project is based on Web Services so is there any other way I
> can use request-scoped
> context with connection pooling or do you have any other alternative better
> then this ?
>
> On Fri, Sep 11, 2015 at 7:46 PM, Dipesh Jain <dipesh@ivgroup.in> wrote:
>
> > 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 <dipesh@ivgroup.in> 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
> >>
> >>     <?xml version="1.0" encoding="utf-8"?>
> >>         <domain project-version="6">
> >>     <property name="cayenne.DataDomain.usingExternalTransactions"
> >> value="true"/>
> >>     <map name="MastersDataMap"/>
> >>     <node name="MastersDataNode"
> >>
> factory="org.apache.cayenne.configuration.server.XMLPoolingDataSourceFactory"
> >>
> schema-update-strategy="org.apache.cayenne.access.dbsync.CreateIfNoSchemaStrategy">
> >>     <map-ref name="MastersDataMap"/>
> >>     <data-source>
> >>     <driver value="net.sourceforge.jtds.jdbc.Driver"/>
> >>     <url value="jdbc:jtds:sqlserver://localhost:1433/test"/>
> >>     <connectionPool min="1" max="30"/>
> >>     <login userName="sa" password="admin@123"/>
> >>     </data-source>
> >>     </node>
> >>     </domain>
> >>
> >> TestDataMap.map.xml
> >>
> >>     <?xml version="1.0" encoding="utf-8"?>
> >>     <data-map xmlns="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">
> >> <property name="defaultPackage" value="com.org.ivcargo.platform.dto"/>
> >> <db-entity name="PersonTemp" schema="dbo" catalog="test">
> >> <db-attribute name="personId" type="NUMERIC" isPrimaryKey="true"
> >> isGenerated="true" isMandatory="true" length="10"/>
> >> <db-attribute name="firstname" type="VARCHAR" length="100"/>
> >> <db-attribute name="lastname" type="VARCHAR" length="100"/>
> >> </db-entity>
> >> <obj-entity name="PersonTemp"
> >> className="com.org.ivcargo.platform.dto.PersonTemp"
> >> dbEntityName="PersonTemp">
> >> <obj-attribute name="personId" type="java.lang.Long" lock="true"
> >> db-attribute-path="personId"/>
> >> <obj-attribute name="firstname" type="java.lang.String"
> >> db-attribute-path="firstname"/>
> >> <obj-attribute name="lastname" type="java.lang.String"
> >> db-attribute-path="lastname"/>
> >> </obj-entity>
> >>     </data-map>
> >>
> >> --
> >> Thanks and Regards
> >> Deepesh Jain
> >>
> >
> >
> >
> > --
> > Thanks and Regards
> > Deepesh Jain
> >
>
>
>
> --
> Thanks and Regards
> Deepesh Jain
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message