You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by pinkybum_nabble <ne...@jdsu.com> on 2007/10/02 23:32:43 UTC

To dep PK

I have only been looking into this tool for a couple of days now and I am
finding it great to work with and easy to use. However, I have been having
an issue which may be my ignorance of database relationships. I have defined
dbEntities and relationships much like:

MasterEntity
DependentEntity

The relationship is One-to-many (one Master to Many Dependents)

I have created the analogous object entities. When I manipulate these
objects in java using code like:

		Master mas = null;
		Dependent dep1 = null;
		Dependent dep2 = null;
		mas = (Master)context.newObject( Master.class );
		mas.setNumber( Integer.valueOf( 100 ));
		dep1 = (Dependents)context.newObject( Dependents.class );
		dep1.setName( "DependentNumber A");
		mas.addToDependents( dep1 );
		dep2 = (Dependents)context.newObject( Dependents.class );
		dep2.setName( "DependentNumber B");
		mas.addToDependents( dep2 );
		
		context.commitChanges();
		
I get an exception which indicates that the database tried to create a
Dependent entry with a duplicate primary key. The only configuration which
alleviates this problem and creates unique Dependent keys is checking the
"To dep PK" checkbox on the dependent side of the relationship. Reading the
documentation it seems to suggest that the checkbox should be checked on the
master side of the relationship. Did I just read wrongly, can't I just leave
the checkbox blank or is there some other configuration I am missing when I
create my schemas? I would like to get this issue resolved before adding
full database support to the project via Cayenne and deploying the
production database.

Many Thankls
Neil Pinkerton

-- 
View this message in context: http://www.nabble.com/To-dep-PK-tf4558289.html#a13008451
Sent from the Cayenne - User mailing list archive at Nabble.com.


Re: To dep PK

Posted by Aristedes Maniatis <ar...@maniatis.org>.
On 03/10/2007, at 9:25 AM, pinkybum_nabble wrote:

> I have unchecked all the "To dep PK" boxes. The PK generation  
> setting is
> default. The log output is as follows:
>
> INFO  QueryLogger: INSERT INTO ScanFiles (SCANFILE_ID, name) VALUES  
> (?, ?)
> INFO  QueryLogger: [bind: 200, 'ScanNumber B1']
> INFO  QueryLogger: === updated 1 row.
> INFO  QueryLogger: [bind: 200, 'ScanNumber A1']
> INFO  QueryLogger: *** error.
>
> It seems the PK generator is creating a duplicate SCANFILE_ID of  
> 200 (which
> is the default starting value in  AUTO_PK_SUPPORT.

OK. This looks like you've identified the underlying problem. But I  
can't imagine the cause of this problem, maybe someone else has  
ideas. Do you have:

* PK ticked in the model for the correct fields?
* a table which looks like CREATE TABLE AUTO_PK_SUPPORT (  TABLE_NAME  
CHAR(100) NOT NULL,  NEXT_ID INTEGER NOT NULL,  PRIMARY KEY(TABLE_NAME))
* is AUTO_PK_SUPPORT writable by the application?


Maybe you could work through the tutorial and see how your model  
differs:

http://cayenne.apache.org/doc/quick-start.html



Ari Maniatis





-------------------------->
Aristedes Maniatis
phone +61 2 9660 9700
PGP fingerprint 08 57 20 4B 80 69 59 E2  A9 BF 2D 48 C2 20 0C C8



Re: To dep PK

Posted by pinkybum_nabble <ne...@jdsu.com>.
I have unchecked all the "To dep PK" boxes. The PK generation setting is
default. The log output is as follows:

INFO  QueryLogger: INSERT INTO ScanFiles (SCANFILE_ID, name) VALUES (?, ?)
INFO  QueryLogger: [bind: 200, 'ScanNumber B1']
INFO  QueryLogger: === updated 1 row.
INFO  QueryLogger: [bind: 200, 'ScanNumber A1']
INFO  QueryLogger: *** error.

It seems the PK generator is creating a duplicate SCANFILE_ID of 200 (which
is the default starting value in  AUTO_PK_SUPPORT.

Neil


Aristedes Maniatis-2 wrote:
> 
> 
> On 03/10/2007, at 7:32 AM, pinkybum_nabble wrote:
> 
>> I get an exception which indicates that the database tried to create a
>> Dependent entry with a duplicate primary key. The only  
>> configuration which
>> alleviates this problem and creates unique Dependent keys is  
>> checking the
>> "To dep PK" checkbox on the dependent side of the relationship.
> 
> This should not be ticked in ordinary use. It is for special cases  
> such as a one-to-one relationship model.
> 
> http://cayenne.apache.org/doc/to-dep-pk-checkbox.html
> 
> I'd be looking at your primary key generation strategy. Are you using  
> the default? What key is being created in the database once you add  
> and commit one record?
> 
> 
> Ari Maniatis
> 
> 
> 
> -------------------------->
> Aristedes Maniatis
> phone +61 2 9660 9700
> PGP fingerprint 08 57 20 4B 80 69 59 E2  A9 BF 2D 48 C2 20 0C C8
> 
> 
> 
>  
> 

-- 
View this message in context: http://www.nabble.com/To-dep-PK-tf4558289.html#a13010250
Sent from the Cayenne - User mailing list archive at Nabble.com.


Re: To dep PK

Posted by Aristedes Maniatis <ar...@maniatis.org>.
On 03/10/2007, at 7:32 AM, pinkybum_nabble wrote:

> I get an exception which indicates that the database tried to create a
> Dependent entry with a duplicate primary key. The only  
> configuration which
> alleviates this problem and creates unique Dependent keys is  
> checking the
> "To dep PK" checkbox on the dependent side of the relationship.

This should not be ticked in ordinary use. It is for special cases  
such as a one-to-one relationship model.

http://cayenne.apache.org/doc/to-dep-pk-checkbox.html

I'd be looking at your primary key generation strategy. Are you using  
the default? What key is being created in the database once you add  
and commit one record?


Ari Maniatis



-------------------------->
Aristedes Maniatis
phone +61 2 9660 9700
PGP fingerprint 08 57 20 4B 80 69 59 E2  A9 BF 2D 48 C2 20 0C C8



Re: To dep PK

Posted by Michael Gentry <bl...@gmail.com>.
Hi Neil, I'll send you an example model off-list since the mailing
list doesn't support attachments.

/dev/mrg


On 10/2/07, pinkybum_nabble <ne...@jdsu.com> wrote:
>
> I have only been looking into this tool for a couple of days now and I am
> finding it great to work with and easy to use. However, I have been having
> an issue which may be my ignorance of database relationships. I have defined
> dbEntities and relationships much like:
>
> MasterEntity
> DependentEntity
>
> The relationship is One-to-many (one Master to Many Dependents)
>
> I have created the analogous object entities. When I manipulate these
> objects in java using code like:
>
>                 Master mas = null;
>                 Dependent dep1 = null;
>                 Dependent dep2 = null;
>                 mas = (Master)context.newObject( Master.class );
>                 mas.setNumber( Integer.valueOf( 100 ));
>                 dep1 = (Dependents)context.newObject( Dependents.class );
>                 dep1.setName( "DependentNumber A");
>                 mas.addToDependents( dep1 );
>                 dep2 = (Dependents)context.newObject( Dependents.class );
>                 dep2.setName( "DependentNumber B");
>                 mas.addToDependents( dep2 );
>
>                 context.commitChanges();
>
> I get an exception which indicates that the database tried to create a
> Dependent entry with a duplicate primary key. The only configuration which
> alleviates this problem and creates unique Dependent keys is checking the
> "To dep PK" checkbox on the dependent side of the relationship. Reading the
> documentation it seems to suggest that the checkbox should be checked on the
> master side of the relationship. Did I just read wrongly, can't I just leave
> the checkbox blank or is there some other configuration I am missing when I
> create my schemas? I would like to get this issue resolved before adding
> full database support to the project via Cayenne and deploying the
> production database.
>
> Many Thankls
> Neil Pinkerton
>
> --
> View this message in context: http://www.nabble.com/To-dep-PK-tf4558289.html#a13008451
> Sent from the Cayenne - User mailing list archive at Nabble.com.
>
>