You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Joose Vettenranta <jo...@iki.fi> on 2004/07/23 12:14:05 UTC

Still can't get 1:n to work.

I checked that sample files I got and checked the website and googled  
like maniac.. And still not getting anywhere..

Is it realy this difficult or have I just missed something? I have now  
tried about 30h to make this work but still no luck.

Current status:

- Getting data from database to beans [just does select too many times  
and get's next sequence, but not really a problem yet]
- Updating data does does not work:
   + it does UPDATE to file_categories (Category) but INSERT on  
category_names (CategoryName)
   + does not have correct category_id while doing INSERT (which it  
should never do)
- Deleting data does not work (referential integrity violation)
   + it tries to delete first from file_categories (Category) ->  
referential error because there is data in category_names  
(CategoryName)
- Inserting data does not work
   + it does not pass category_id to category_names (CategoryName)
   + does INSERT to the category_names (CategoryName) before  
file_categories (Category) -> if category_id would be passed ->  
referential error

I made database simplier to like this:

CREATE TABLE file_categories (
  ID SERIAL.
PRIMARY KEY (ID));

CREATE TABLE category_names (
  ID SERIAL,
  CATEGORY_ID INTEGER NOT NULL,
  NAME VARCHAR(50),
PRIMARY KEY (ID),
FOREIGN KEY (CATEGORY_ID) REFERENCES file_categories (ID));

Category.java has:

...
private int id;
pricate Collection names = new ArrayList();
...
setters/getters for id
setters/getters for names

public addNames (CategoryName name) {
  names.add (name);
}
...
------------
CategoryName.java has:
private int id;
private int category_id;
private String name;

and I have getters/setters for everyone of those
---------

repository.xml
<descriptor-repository version="1.0" isolation-level="read-uncommitted">
  <jdbc-connection-descriptor jcd-alias="testdb"  
default-connection="true" platform="PostgreSQL"  
subprotocol="postgresql">
   <sequence-manager  
className="org.apache.ojb.broker.util.sequence.SequenceManagerNextValImp 
l"/>
  </jdbc-connection-descriptor>
  <class-descriptor class="net.vettenranta.category.bean.Category"  
table="FILE_CATEGORIES">
   <field-descriptor name="id"
                                 primarykey="true"
                                 nullable="false"
                                 default-fetch="true"
                                 autoincrement="true"
                                 column="ID"
                                 sequence-name="file_categories_id_seq"
                                 jdbc-type="INTEGER"
                                 access="readonly"/>
    <collection-descriptor name="names"
                                  
element-class-ref="net.vettenranta.category.bean.CategoryName"
                                  
collection- 
class="org.apache.ojb.broker.util.collections.ManageableArrayList"
                                 otm-dependent="true">
                         <inverse-foreignkey field-ref="category_id"/>
    </collection-descriptor>
   </class-descriptor>
   <class-descriptor class="net.vettenranta.category.bean.CategoryName"  
table="CATEGORY_NAMES">
    <field-descriptor name="id"
                                 primarykey="true"
                                 nullable="false"
                                 default-fetch="true"
                                 column="ID"
                                 jdbc-type="INTEGER"
                                 autoincrement="true"
                                 sequence-name="category_names_id_seq"  
access="readonly"/>
        <field-descriptor name="category_id"
                                 nullable="false"
                                 default-fetch="true"
                                 column="CATEGORY_ID"
                                 jdbc-type="INTEGER" />
       <field-descriptor name="name"
                                 default-fetch="true"
                                 column="NAME"
                                 jdbc-type="VARCHAR"/>
  </class-descriptor>
---------------
--
"Always remember that you are unique, just like everyone else!"
* http://iki.fi/joose/ * joose@iki.fi * +358 44 561 0270 *


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: Still can't get 1:n to work.

Posted by Joose Vettenranta <jo...@iki.fi>.
Hi,

I did complete clear from scratch and found out very odd behavior.

I explained whole thing in http://joose.iki.fi/ojb/

Check the results.. It makes those sql-clauses (INSERT or DELETE) in  
random(?) order.

It seem to every second time to create files in OK order but every  
other time in wrong order. Like you can't add children for parent  
before that parent exists.

Thanks,

Joose

23.7.2004 kello 19:43, Carlos Chávez kirjoitti:


>  Hi Joose.
>
> Joose Vettenranta Escribio :-)
>> I checked that sample files I got and checked the website and googled
>> like maniac.. And still not getting anywhere..
>>
>> Is it realy this difficult or have I just missed something? I have now
>> tried about 30h to make this work but still no luck.
>>
>> Current status:
>>
>> - Getting data from database to beans [just does select too many times
>> and get's next sequence, but not really a problem yet]
>> - Updating data does does not work:
>>    + it does UPDATE to file_categories (Category) but INSERT on
>> category_names (CategoryName)
>>    + does not have correct category_id while doing INSERT (which it
>> should never do)
>> - Deleting data does not work (referential integrity violation)
>>    + it tries to delete first from file_categories (Category) ->
>> referential error because there is data in category_names
>> (CategoryName)
>> - Inserting data does not work
>>    + it does not pass category_id to category_names (CategoryName)
>>    + does INSERT to the category_names (CategoryName) before
>> file_categories (Category) -> if category_id would be passed ->
>> referential error
>>
>> I made database simplier to like this:
>>
>> CREATE TABLE file_categories (
>>   ID SERIAL.
>> PRIMARY KEY (ID));
>>
>> CREATE TABLE category_names (
>>   ID SERIAL,
>>   CATEGORY_ID INTEGER NOT NULL,
>>   NAME VARCHAR(50),
>> PRIMARY KEY (ID),
>> FOREIGN KEY (CATEGORY_ID) REFERENCES file_categories (ID));
>>
>> Category.java has:
>>
>> ...
>> private int id;
>> pricate Collection names = new ArrayList();
>> ...
>> setters/getters for id
>> setters/getters for names
>>
>> public addNames (CategoryName name) {
>>   names.add (name);
>> }
>> ...
>> ------------
>> CategoryName.java has:
>> private int id;
>> private int category_id;
>> private String name;
>>
>> and I have getters/setters for everyone of those
>> ---------
>>
>> repository.xml
>> <descriptor-repository version="1.0"  
>> isolation-level="read-uncommitted">
>>   <jdbc-connection-descriptor jcd-alias="testdb"
>> default-connection="true" platform="PostgreSQL"
>> subprotocol="postgresql">
>>    <sequence-manager
>> className="org.apache.ojb.broker.util.sequence.SequenceManagerNextValI 
>> mp
>> l"/>
>>   </jdbc-connection-descriptor>
>>   <class-descriptor class="net.vettenranta.category.bean.Category"
>> table="FILE_CATEGORIES">
>>    <field-descriptor name="id"
>>                                  primarykey="true"
>>                                  nullable="false"
>>                                  default-fetch="true"
>>                                  autoincrement="true"
>>                                  column="ID"
>>                                   
>> sequence-name="file_categories_id_seq"
>>                                  jdbc-type="INTEGER"
>>                                  access="readonly"/>
>>     <collection-descriptor name="names"
>>
>> element-class-ref="net.vettenranta.category.bean.CategoryName"
>>
>> collection-
>> class="org.apache.ojb.broker.util.collections.ManageableArrayList"
>>                                  otm-dependent="true">
>>                          <inverse-foreignkey field-ref="category_id"/>
>
>   in "<inverse-foreignkey field-ref="category_id"/>" i think this is a
>   problem: the field category_id does not exist in the table
>   FILE_CATEGORIES, although the field category_id exist in the table
>   CATEGORY_NAMES.
>
>   This is what I would do:
>   Rename the field "ID" to "CATEGORY_ID" in table file_categories, well
>   of course made the chandes in the repoitory.xml
>
>   There are other attribute in for the "collection-descriptor" element
>   like "auto-update" and "auto-delete" try put to true the value of  
> this
>   attribute.
>
>   Cheers,
>   Carlos Chávez.
>
>>     </collection-descriptor>
>>    </class-descriptor>
>>    <class-descriptor  
>> class="net.vettenranta.category.bean.CategoryName"
>> table="CATEGORY_NAMES">
>>     <field-descriptor name="id"
>>                                  primarykey="true"
>>                                  nullable="false"
>>                                  default-fetch="true"
>>                                  column="ID"
>>                                  jdbc-type="INTEGER"
>>                                  autoincrement="true"
>>                                  sequence-name="category_names_id_seq"
>> access="readonly"/>
>>         <field-descriptor name="category_id"
>>                                  nullable="false"
>>                                  default-fetch="true"
>>                                  column="CATEGORY_ID"
>>                                  jdbc-type="INTEGER" />
>>        <field-descriptor name="name"
>>                                  default-fetch="true"
>>                                  column="NAME"
>>                                  jdbc-type="VARCHAR"/>
>>   </class-descriptor>
>> ---------------
>> --
>> "Always remember that you are unique, just like everyone else!"
>> * http://iki.fi/joose/ * joose@iki.fi * +358 44 561 0270 *
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>
>
>
> -- 
> Carlos Chávez
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
--
"Always remember that you are unique, just like everyone else!"
* http://iki.fi/joose/ * joose@iki.fi * +358 44 561 0270 *


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: Still can't get 1:n to work.

Posted by Carlos Chávez <cc...@agssa.net>.
 Hi Joose.

Joose Vettenranta Escribio :-)
> I checked that sample files I got and checked the website and googled
> like maniac.. And still not getting anywhere..
>
> Is it realy this difficult or have I just missed something? I have now
> tried about 30h to make this work but still no luck.
>
> Current status:
>
> - Getting data from database to beans [just does select too many times
> and get's next sequence, but not really a problem yet]
> - Updating data does does not work:
>    + it does UPDATE to file_categories (Category) but INSERT on
> category_names (CategoryName)
>    + does not have correct category_id while doing INSERT (which it
> should never do)
> - Deleting data does not work (referential integrity violation)
>    + it tries to delete first from file_categories (Category) ->
> referential error because there is data in category_names
> (CategoryName)
> - Inserting data does not work
>    + it does not pass category_id to category_names (CategoryName)
>    + does INSERT to the category_names (CategoryName) before
> file_categories (Category) -> if category_id would be passed ->
> referential error
>
> I made database simplier to like this:
>
> CREATE TABLE file_categories (
>   ID SERIAL.
> PRIMARY KEY (ID));
>
> CREATE TABLE category_names (
>   ID SERIAL,
>   CATEGORY_ID INTEGER NOT NULL,
>   NAME VARCHAR(50),
> PRIMARY KEY (ID),
> FOREIGN KEY (CATEGORY_ID) REFERENCES file_categories (ID));
>
> Category.java has:
>
> ...
> private int id;
> pricate Collection names = new ArrayList();
> ...
> setters/getters for id
> setters/getters for names
>
> public addNames (CategoryName name) {
>   names.add (name);
> }
> ...
> ------------
> CategoryName.java has:
> private int id;
> private int category_id;
> private String name;
>
> and I have getters/setters for everyone of those
> ---------
>
> repository.xml
> <descriptor-repository version="1.0" isolation-level="read-uncommitted">
>   <jdbc-connection-descriptor jcd-alias="testdb"
> default-connection="true" platform="PostgreSQL"
> subprotocol="postgresql">
>    <sequence-manager
> className="org.apache.ojb.broker.util.sequence.SequenceManagerNextValImp
> l"/>
>   </jdbc-connection-descriptor>
>   <class-descriptor class="net.vettenranta.category.bean.Category"
> table="FILE_CATEGORIES">
>    <field-descriptor name="id"
>                                  primarykey="true"
>                                  nullable="false"
>                                  default-fetch="true"
>                                  autoincrement="true"
>                                  column="ID"
>                                  sequence-name="file_categories_id_seq"
>                                  jdbc-type="INTEGER"
>                                  access="readonly"/>
>     <collection-descriptor name="names"
>
> element-class-ref="net.vettenranta.category.bean.CategoryName"
>
> collection-
> class="org.apache.ojb.broker.util.collections.ManageableArrayList"
>                                  otm-dependent="true">
>                          <inverse-foreignkey field-ref="category_id"/>

  in "<inverse-foreignkey field-ref="category_id"/>" i think this is a
  problem: the field category_id does not exist in the table
  FILE_CATEGORIES, although the field category_id exist in the table
  CATEGORY_NAMES.

  This is what I would do:
  Rename the field "ID" to "CATEGORY_ID" in table file_categories, well
  of course made the chandes in the repoitory.xml

  There are other attribute in for the "collection-descriptor" element
  like "auto-update" and "auto-delete" try put to true the value of this
  attribute.

  Cheers,
  Carlos Chávez.

>     </collection-descriptor>
>    </class-descriptor>
>    <class-descriptor class="net.vettenranta.category.bean.CategoryName"
> table="CATEGORY_NAMES">
>     <field-descriptor name="id"
>                                  primarykey="true"
>                                  nullable="false"
>                                  default-fetch="true"
>                                  column="ID"
>                                  jdbc-type="INTEGER"
>                                  autoincrement="true"
>                                  sequence-name="category_names_id_seq"
> access="readonly"/>
>         <field-descriptor name="category_id"
>                                  nullable="false"
>                                  default-fetch="true"
>                                  column="CATEGORY_ID"
>                                  jdbc-type="INTEGER" />
>        <field-descriptor name="name"
>                                  default-fetch="true"
>                                  column="NAME"
>                                  jdbc-type="VARCHAR"/>
>   </class-descriptor>
> ---------------
> --
> "Always remember that you are unique, just like everyone else!"
> * http://iki.fi/joose/ * joose@iki.fi * +358 44 561 0270 *
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>


-- 
Carlos Chávez

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org