cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "" <>
Subject R: Re: splitted class into separate table
Date Wed, 16 Nov 2011 12:54:51 GMT
Hi Andrus, 

I'm using MySQL 5.1.  In this case flattened attributes works fine in a brand 
new database created by Cayenne, but not in a legacy schema where USERS has 
auto_generated <<PK>> and ACCOUNTS has normally assigned <<PK>>. I
have set 
(one-to-one) toDep aware relationship from users(master) table to accounts
(dependent) table but saving User instance  
throws thi exception:    Column 'user_id' cannot be null
actually the logger says:
 INSERT INTO USERS (lastname, firstname) VALUES (?, ?)
 INFO: [bind: 1->lastname '...', 2->firstname:'...']

 INSERT INTO ACCOUNTS (email, id_commerciale, password, username) VALUES (?, 
?, ?, ?)
 INFO: [batch bind: 1->email:'',    2->user_id:NULL,     3-
>password:'c...', 4->username:'...']

 Do I necessarily have to create AUTO_PK_SUPPORT table in this scenario? 


>----Messaggio originale----
>Data: 16/11/2011 8.18
>A: <>
>Ogg: Re: splitted class into separate table
>Hi there,
>You can map this in Cayenne via "flattened attributes" across a 
>You'd start by mapping both tables as DbEntities, and creating 1..1 
DbRelationship between them. After that you map Users ObjEntity, and then add 
"flattened attributes" to it, mapped to the related DbEntity columns. You can 
check vertical inheritance article for the details of this technique (even 
though you don't have inheritance here, flattened attributes are mapped 
similarly) : 
>On Nov 15, 2011, at 7:11 PM, wrote:
>> Suppose that in legacy schema,that you are working on getting
>> Cayenne to work with, you aren't keeping all the information about
>> user with the user's main information in the users table, but in a
>> separate table.
>> For example:
>> <<table users>>
>> id
>> firstname
>> lastname
>> <<table accounts>>
>> user_id <<PK>><<FK>>
>> username
>> password
>> email
>> In my domain I wish to have User model with all properties firstname,
>> username,email,password 
>> without create class model related to accounts table and relative
>> association. Is there a way to do this with Cayenne ? can someone please 
>> me a xml example? 

View raw message