You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Lucas Holt <lu...@foolishgames.com> on 2009/09/10 17:07:03 UTC

Strange behavior with Cayenne

I have a table, projects, that consistently causes me grief with Cayenne. 
When creating a new object, it seems to work but never changes the state
of the object in cayenne.  Thus, next time I try to do any operation
requiring commitChanges(), it tries to insert the record again and fails.

I can't figure out what is wrong.  I found that after the commit I can do
a rollback to clean up the state, but I suspect there's something else
happening.  This was initially occurring with 2.0.4, so I switched over to
Cayenne 3.0M6 last night.  The same behavior is occurring with the new
version.

Here's the create code:
...
proj = (Projects) dataContext.newObject(Projects.class);
proj.setProjectName(projectName);
proj.setCompany(company);
proj.setOffice(office);
proj.setStartDate(startDate);
dataContext.commitChanges();
...

dataContext is created with  dataContext =
DataContext.getThreadDataContext(); above (and initialized with a filter
in the servlet container)

I've used Cayenne Modeler to setup the relationships.

Here's the map for that table (with only the catalog name changed)

   <db-entity name="projects" catalog="hiddentoprojectinnocent">
                <db-attribute name="company_id" type="TINYINT"
isMandatory="true"/>
                <db-attribute name="office_id" type="SMALLINT"
isMandatory="true"/>
                <db-attribute name="project_id" type="BIGINT"
isPrimaryKey="true" isGenerated="true" isMandatory="true"
length="10"/>
                <db-attribute name="project_name" type="VARCHAR"
isMandatory="true" length="255"/>
                <db-attribute name="start_date" type="DATE"/>
        </db-entity>

No cayenne exceptions are getting thrown when I call commitChanges()
initially.

The environment is MySQL 5.1.35, Tomcat 6.0.20, Java 6, Apache Click

Re: Strange behavior with Cayenne

Posted by Lucas Holt <lu...@foolishgames.com>.
Thanks.  I found the problem was in the code calling this.

On Sep 10, 2009, at 11:42 AM, Michael Gentry wrote:

> That looks pretty good to me (I do the same types of things just
> fine).  Are company/office in the same DataContext?
>
> mrg
>



Lucas Holt
Luke@FoolishGames.com
________________________________________________________
MidnightBSD.org (Free OS)
JustJournal.com (Free blogging)





Re: Strange behavior with Cayenne

Posted by Michael Gentry <mg...@masslight.net>.
That looks pretty good to me (I do the same types of things just
fine).  Are company/office in the same DataContext?

mrg


On Thu, Sep 10, 2009 at 11:07 AM, Lucas Holt<lu...@foolishgames.com> wrote:
> I have a table, projects, that consistently causes me grief with Cayenne.
> When creating a new object, it seems to work but never changes the state
> of the object in cayenne.  Thus, next time I try to do any operation
> requiring commitChanges(), it tries to insert the record again and fails.
>
> I can't figure out what is wrong.  I found that after the commit I can do
> a rollback to clean up the state, but I suspect there's something else
> happening.  This was initially occurring with 2.0.4, so I switched over to
> Cayenne 3.0M6 last night.  The same behavior is occurring with the new
> version.
>
> Here's the create code:
> ...
> proj = (Projects) dataContext.newObject(Projects.class);
> proj.setProjectName(projectName);
> proj.setCompany(company);
> proj.setOffice(office);
> proj.setStartDate(startDate);
> dataContext.commitChanges();
> ...
>
> dataContext is created with  dataContext =
> DataContext.getThreadDataContext(); above (and initialized with a filter
> in the servlet container)
>
> I've used Cayenne Modeler to setup the relationships.
>
> Here's the map for that table (with only the catalog name changed)
>
>   <db-entity name="projects" catalog="hiddentoprojectinnocent">
>                <db-attribute name="company_id" type="TINYINT"
> isMandatory="true"/>
>                <db-attribute name="office_id" type="SMALLINT"
> isMandatory="true"/>
>                <db-attribute name="project_id" type="BIGINT"
> isPrimaryKey="true" isGenerated="true" isMandatory="true"
> length="10"/>
>                <db-attribute name="project_name" type="VARCHAR"
> isMandatory="true" length="255"/>
>                <db-attribute name="start_date" type="DATE"/>
>        </db-entity>
>
> No cayenne exceptions are getting thrown when I call commitChanges()
> initially.
>
> The environment is MySQL 5.1.35, Tomcat 6.0.20, Java 6, Apache Click
>