cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Philip Copeland <pcopel...@avoka.com>
Subject Re: Query at the time of inserting data using Apache Cayenne
Date Wed, 09 Sep 2015 16:52:28 GMT
Unsubscribe

Sent from Outlook<http://aka.ms/Ox5hz3>




On Wed, Sep 9, 2015 at 9:27 AM -0700, "Dipesh Jain" <dipesh@ivgroup.in<mailto: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

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