Re: [JBoss-dev] 1 to Many Relations
Uncle. It seems that JBOSS is designed assuming that it has full control of creating tables. Well in my case I already have a database allready set up so my view of things is how do I stuff this database into JBOSS. I don't think it is worth the discussion which approach is right or wrong but, we should document the view jboss takes and then write appropriate documention for the other approach. Dain if you could get at DTD for jbosscmp-jdbc.xml I'll tidy up xdoclet and write some documentation for I've got these tables now how do I do relations in JBOSS. This should eliminate this thread occurring over and over on the user mailing lists. Dave Dain Sundstrom wrote: If I use the jbosscmp-jdbc.xml file I can get it to work. Do you have to use the jbosscmp-jdbc.xml file? If you don't, what happens? Does the system generate two columns with the same name? The database table already exsists. Basically I have to use foreign-key-fields and set field-name and column-name attributes the same. Ok, now we are getting somewhere. If you want to use an existing database structure you must tell JBossCMP about it. JAWS had the same requirement. If your database happens to work by default, well you were lucky. We make no gaurentees that JBossCMP will map by default the way you want. We may decide that a default name was stupid and change it. Let make this very very very very clear. All column names are either generated, or specified in the jbosscmp-jdbc.xml file. All column names are either generated, or specified in the jbosscmp-jdbc.xml file. Your opinion is that when jboss generates the column name for a relationship fk it should first attempt to the name of the cmr-field abstract accessors. Problems occur when the entity does not have an accessor for the relationship, and when the primary key related entity maps to more then one db column. What is your complete proposal for fk column generation and relation-table column generation? Be specific. Not quite I suggest you use the name of the cmr-field-name in the ejb-relationship. therefore when creating the column the field always has to be there. What about many-to-one unidirectiona relationships that wish to use a fk? Now after great thought how do you keep the columns straight in a multi column pk? So if table1 has a primary key of a,b,c and the foregin key in the table2 is e,f,g and then to find the key a=g,b=f and c=e how do you specify this now? There is no guarantee on the order the fields are pulled out of the primary key. Is the order we specify them in the cmp-fieldfield-name have to be the same on both sides of the relation? Once you answer this I can pull the rest of the proposal together. Order has nothing to do with this. Each pk field is mapped by name in the foreign-key-fields element or the table-fields element. foreign-key-fields foreign-key-field field-namea/field-name column-namee/column-name /foreign-key-field foreign-key-field field-nameb/field-name column-namef/column-name /foreign-key-field foreign-key-field field-namec/field-name column-nameg/column-name /foreign-key-field /foreign-key-fields All of this information is mainatined in the field objects (see the bridge package). -dain ___ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development ___ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development
RE: [JBoss-dev] 1 to Many Relations
Uncle. It seems that JBOSS is designed assuming that it has full control of creating tables. This isn't really true. JBossCMP makes the assumption that if the table structure is not specified the Application Deployer does not care what the structure is, as long as it runs. I strongly recommend that before any application goes into production that the database structure should be locked down (full specified), as the defaults may change from version to version. Well in my case I already have a database already set up so my view of things is how do I stuff this database into JBOSS. I don't think it is worth the discussion which approach is right or wrong but, we should document the view jboss takes and then write appropriate documention for the other approach. Dain if you could get at DTD for jbosscmp-jdbc.xml I'll tidy up xdoclet and write some documentation for I've got these tables now how do I do relations in JBOSS. This should eliminate this thread occurring over and over on the user mailing lists. Dave I agree, I have already started on an appendix to the JBossCMP docs that specifies the default names. -dain ___ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development
Re: [JBoss-dev] 1 to Many Relations
Ok, you are not getting it. I am it's just that the moon is gone ;) Although JBossCMP does not generate the column names you would like, the system still runs. Is that correct? (i.e., this is still a suggestion) If I use the jbosscmp-jdbc.xml file I can get it to work. Ok now that we agree on that. How would you like the column names generated? Be very very specific and take into consideraton the above problems. I do no want jboss to generate any column names. It's not necessary. Either the class field is the database column name or in jbosscmp-jdbc.xml you specify that class field x maps to database column y. If there is a name space collision then it is a database setup problem not JBOSS's and we should not be coding for it. As for my comment easy to code, that is perfectly valid, as we are shooting for CMP 2.0 compliance. CMP 2.0 is a huge spec, so everything can not be perfect in the first pass. Some of the implementation details get implemnted the easy way. There have to be priorities. Yup, it's just this one looks like something that will fill the mailing lists. If you pulled togther your test cases then I could probably have a look, you do not have to do this whole thing by yourself. ___ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development
Re: [JBoss-dev] 1 to Many Relations
Hi guys, I've just been skimming this thread, but it strikes me as possible that it is based on a misunderstanding. Dave, do you know that you should not define a cmp field for a foreign key column? So changing the naming convention wouldn't be necessary to get it to work by default. Sorry if this is not the problem, and I have missed the point. If so, please just ignore me. -Dan On 19 Nov 01, at 11:05, Dave Smith wrote: Ok, you are not getting it. I am it's just that the moon is gone ;) Although JBossCMP does not generate the column names you would like, the system still runs. Is that correct? (i.e., this is still a suggestion) If I use the jbosscmp-jdbc.xml file I can get it to work. Ok now that we agree on that. How would you like the column names generated? Be very very specific and take into consideraton the above problems. I do no want jboss to generate any column names. It's not necessary. Either the class field is the database column name or in jbosscmp-jdbc.xml you specify that class field x maps to database column y. If there is a name space collision then it is a database setup problem not JBOSS's and we should not be coding for it. As for my comment easy to code, that is perfectly valid, as we are shooting for CMP 2.0 compliance. CMP 2.0 is a huge spec, so everything can not be perfect in the first pass. Some of the implementation details get implemnted the easy way. There have to be priorities. Yup, it's just this one looks like something that will fill the mailing lists. If you pulled togther your test cases then I could probably have a look, you do not have to do this whole thing by yourself. ___ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development ___ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development
Re: [JBoss-dev] 1 to Many Relations
Don't be sorry, be happy ;) the problem is that the name specified in the cmr-field-name is not the database column. Jboss assumes that the database column name is the cmr_field_name (left side) +_ + cmr_field_name right side. What I think makes more sense is for the cmr_field_name by default to match the database column name the same way it does in CMP. Dan OConnor wrote: Hi guys, I've just been skimming this thread, but it strikes me as possible that it is based on a misunderstanding. Dave, do you know that you should not define a cmp field for a foreign key column? So changing the naming convention wouldn't be necessary to get it to work by default. Sorry if this is not the problem, and I have missed the point. If so, please just ignore me. -Dan On 19 Nov 01, at 11:05, Dave Smith wrote: e.net https://lists.sourceforge.net/lists/listinfo/jboss-development ___ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development
RE: [JBoss-dev] 1 to Many Relations
Ok, you are not getting it. I am it's just that the moon is gone ;) Although JBossCMP does not generate the column names you would like, the system still runs. Is that correct? (i.e., this is still a suggestion) If I use the jbosscmp-jdbc.xml file I can get it to work. Do you have to use the jbosscmp-jdbc.xml file? If you don't, what happens? Does the system generate two columns with the same name? Ok now that we agree on that. How would you like the column names generated? Be very very specific and take into consideraton the above problems. I do no want jboss to generate any column names. It's not necessary. Either the class field is the database column name or in jbosscmp-jdbc.xml you specify that class field x maps to database column y. If there is a name space collision then it is a database setup problem not JBOSS's and we should not be coding for it. All column names are either generated, or specified in the jbosscmp-jdbc.xml file. Your opinion is that when jboss generates the column name for a relationship fk it should first attempt to the name of the cmr-field abstract accessors. Problems occur when the entity does not have an accessor for the relationship, and when the primary key related entity maps to more then one db column. What is your complete proposal for fk column generation and relation-table column generation? Be specific. As for my comment easy to code, that is perfectly valid, as we are shooting for CMP 2.0 compliance. CMP 2.0 is a huge spec, so everything can not be perfect in the first pass. Some of the implementation details get implemnted the easy way. There have to be priorities. Yup, it's just this one looks like something that will fill the mailing lists. If you pulled together your test cases then I could probably have a look, you do not have to do this whole thing by yourself. I know. I am working on the todo list right now (which will be posted to sf), and after that I will be adding my test cases. For now, what is your proposal? -dain ___ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development
Re: [JBoss-dev] 1 to Many Relations
If I use the jbosscmp-jdbc.xml file I can get it to work. Do you have to use the jbosscmp-jdbc.xml file? If you don't, what happens? Does the system generate two columns with the same name? The database table already exsists. Basically I have to use foreign-key-fields and set field-name and column-name attributes the same. Ok now that we agree on that. How would you like the column names generated? Be very very specific and take into consideraton the above problems. I do no want jboss to generate any column names. It's not necessary. Either the class field is the database column name or in jbosscmp-jdbc.xml you specify that class field x maps to database column y. If there is a name space collision then it is a database setup problem not JBOSS's and we should not be coding for it. All column names are either generated, or specified in the jbosscmp-jdbc.xml file. Your opinion is that when jboss generates the column name for a relationship fk it should first attempt to the name of the cmr-field abstract accessors. Problems occur when the entity does not have an accessor for the relationship, and when the primary key related entity maps to more then one db column. What is your complete proposal for fk column generation and relation-table column generation? Be specific. Not quite I suggest you use the name of the cmr-field-name in the ejb-relationship. therefore when creating the column the field always has to be there. Now after great thought how do you keep the columns straight in a multi column pk? So if table1 has a primary key of a,b,c and the foregin key in the table2 is e,f,g and then to find the key a=g,b=f and c=e how do you specify this now? There is no guarantee on the order the fields are pulled out of the primary key. Is the order we specify them in the cmp-fieldfield-name have to be the same on both sides of the relation? Once you answer this I can pull the rest of the proposal together. As for my comment easy to code, that is perfectly valid, as we are shooting for CMP 2.0 compliance. CMP 2.0 is a huge spec, so everything can not be perfect in the first pass. Some of the implementation details get implemnted the easy way. There have to be priorities. Yup, it's just this one looks like something that will fill the mailing lists. If you pulled together your test cases then I could probably have a look, you do not have to do this whole thing by yourself. I know. I am working on the todo list right now (which will be posted to sf), and after that I will be adding my test cases. For now, what is your proposal? -dain ___ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development
RE: [JBoss-dev] 1 to Many Relations
If I use the jbosscmp-jdbc.xml file I can get it to work. Do you have to use the jbosscmp-jdbc.xml file? If you don't, what happens? Does the system generate two columns with the same name? The database table already exsists. Basically I have to use foreign-key-fields and set field-name and column-name attributes the same. Ok, now we are getting somewhere. If you want to use an existing database structure you must tell JBossCMP about it. JAWS had the same requirement. If your database happens to work by default, well you were lucky. We make no gaurentees that JBossCMP will map by default the way you want. We may decide that a default name was stupid and change it. Let make this very very very very clear. All column names are either generated, or specified in the jbosscmp-jdbc.xml file. All column names are either generated, or specified in the jbosscmp-jdbc.xml file. Your opinion is that when jboss generates the column name for a relationship fk it should first attempt to the name of the cmr-field abstract accessors. Problems occur when the entity does not have an accessor for the relationship, and when the primary key related entity maps to more then one db column. What is your complete proposal for fk column generation and relation-table column generation? Be specific. Not quite I suggest you use the name of the cmr-field-name in the ejb-relationship. therefore when creating the column the field always has to be there. What about many-to-one unidirectiona relationships that wish to use a fk? Now after great thought how do you keep the columns straight in a multi column pk? So if table1 has a primary key of a,b,c and the foregin key in the table2 is e,f,g and then to find the key a=g,b=f and c=e how do you specify this now? There is no guarantee on the order the fields are pulled out of the primary key. Is the order we specify them in the cmp-fieldfield-name have to be the same on both sides of the relation? Once you answer this I can pull the rest of the proposal together. Order has nothing to do with this. Each pk field is mapped by name in the foreign-key-fields element or the table-fields element. foreign-key-fields foreign-key-field field-namea/field-name column-namee/column-name /foreign-key-field foreign-key-field field-nameb/field-name column-namef/column-name /foreign-key-field foreign-key-field field-namec/field-name column-nameg/column-name /foreign-key-field /foreign-key-fields All of this information is mainatined in the field objects (see the bridge package). -dain ___ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development
RE: [JBoss-dev] 1 to Many Relations
Finally, we are on the same page ..not even a blue moon ... About time :) Yup this is a suggestion. I agree 100% we need to avoid using jbosscmp-jdbc.xml. Ultimately at the database level for each table there has to be a unique column name(s) that acts as a foreign key for the relation. It also can only participate in 1 relation. What? Did you really mean that a table can only participate in 1 relationship? For a many to many relationship with a mapping table could be a problem if the field name on both sides of the relationship were the same. But I would see this as an exception not the rule. For self joins you would have to do like you do in the EJBQL and prefix the column with the table name. Not a bad idea for all relations so select uuid from CDTrack where composer=? would be select c.uuid from CDTrack as c where c.composer=? agreed. The column names are constructed to make the code easier to write. There are a lot of cases you are forgetting. Here is a short list: Many side does not have an accessor, so no name to use. One side has a complex pk. One side uses a DVC for a pk. One side has a complex pk which uses a DVC. So what rules do you propose for the fk case. For relation tables, you have the additional problem of name collision between the entities. It is very common to have all entities to use a pk named id or oid. This is not a high priority for me, so what system do you propose? -dain ___ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development
Re: [JBoss-dev] 1 to Many Relations
Dain Sundstrom wrote: OK i'm playing with the latest RH CVS and testing out 1 to many relations (bi directional). So .. Table1 { primary_key int, } TableMany { primary_key int, table1_key int, } class Table1 { int getPrimary_key() Collection getTableMany(); } class TableMany { int getPrimary_key(); int getTable1_key(); } the problem is that when it tries to fetch TableMany it looks for a field called table1_key_primary_key. It would seem that the default key should not be made up but the foreign key of the other side of the relationship. So line 80 of JDBCRelationshipRoleMetaData.java should just be tempCmrFieldName = relatedRole.getEntityName(); 1. Defaults can be overridden. This is the default case. The strange cases should be overridden. Read Marc's bit about packaging. 2. What happens when you have two one-to-many relationships between Table1 and TableMany? Doesn't matter you still need Table1's primary key in TableMany. So you would have Table1 { Collection getTableMany(); Collectiont getTableMany2(); } TableMany { int getTable1_key(); int getTable2_2_key(); } ___ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development
RE: [JBoss-dev] 1 to Many Relations
Dain Sundstrom wrote: OK i'm playing with the latest RH CVS and testing out 1 to many relations (bi directional). So .. Table1 { primary_key int, } TableMany { primary_key int, table1_key int, } class Table1 { int getPrimary_key() Collection getTableMany(); } class TableMany { int getPrimary_key(); int getTable1_key(); } the problem is that when it tries to fetch TableMany it looks for a field called table1_key_primary_key. It would seem that the default key should not be made up but the foreign key of the other side of the relationship. So line 80 of JDBCRelationshipRoleMetaData.java should just be tempCmrFieldName = relatedRole.getEntityName(); 1. Defaults can be overridden. This is the default case. The strange cases should be overridden. Read Marc's bit about packaging. What bit about packaging? 2. What happens when you have two one-to-many relationships between Table1 and TableMany? Doesn't matter you still need Table1's primary key in TableMany. So you would have Table1 { Collection getTableMany(); Collectiont getTableMany2(); } TableMany { int getTable1_key(); int getTable2_2_key(); } You have lost me. What is the problem? Let us clean up the example: Musician { String name; // pk Collection getComposedSongs(); Collection getPreformedSongs(); } CDTrack { String uuid; // pk Musician getComposer(); Musician getPerformer(); } You would get the following table: Musician { name } CDTrack { uuid, musician_composer_name, musician_performer_name } As you can see you get fk with the following pattern: related_entity_name_cmr_field_name_related_entity_pk_field_name unless the many side does not have a cmr field for the relationshiop then you get: related_entity_name_related_cmr_field_name_related_entity_pk_field_name Or am I answering the wrong question? -dain ___ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development
RE: [JBoss-dev] 1 to Many Relations
I'm using xdoclet to generate the ejb-jar.xml file. When you are generating the accessor methods it automaticly assumes that the accessor name matches the database column name. So in your example by default it is looking for a database columns named composer and performer. This is a packaging issue, ie how much work and how confusing is it to generate the ejb-jar.xml files. From my point of view I think that the simplist case is that each database column has a matching get/set method . So in xdoclet .. Musician { String name; // pk /** @ejb:persist-field @ejb:relation name=songs_composer */ Collection getComposedSongs(); } CDTrack { String uuid; // pk /** @ejb:persist-field @ejb:relation name=songs_composer */ Musician getComposer(); } Generates ejb-relation ejb-relation-namesongs_composer/ejb-relation-name ejb-relationship-role multiplicityMany/multiplicity relationship-role-source ejb-nameCDTrack/ejb-name /relationship-role-source cmr-field cmr-field-namecomposer/cmr-field-name /cmr-field /ejb-relationship-role ejb-relationship-role multiplicityOne/multiplicity relationship-role-source ejb-nameMusician/ejb-name /relationship-role-source cmr-field cmr-field-nameCDTrack/cmr-field-name cmr-field-typejava.util.Collection/cmr-field-type /cmr-field /ejb-relationship-role /ejb-relation Tables .. Musician { String name; } CDTrack { String uuid; String composer; } Got it? So what is the problem? Table mapping is an implementation detail. Does the above not deploy? Is ejb-doclet generating bad ddl? -dain ___ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development
Re: [JBoss-dev] 1 to Many Relations
When it tries to load the CDTrack relation it generates the following sql statement .. select uuid from CDTrack where composer_composed_songs=? should be .. select uuid from CDTrack where composer=? Dain Sundstrom wrote: I'm using xdoclet to generate the ejb-jar.xml file. When you are generating the accessor methods it automaticly assumes that the accessor name matches the database column name. So in your example by default it is looking for a database columns named composer and performer. This is a packaging issue, ie how much work and how confusing is it to generate the ejb-jar.xml files. From my point of view I think that the simplist case is that each database column has a matching get/set method . So in xdoclet .. Musician { String name; // pk /** @ejb:persist-field @ejb:relation name=songs_composer */ Collection getComposedSongs(); } CDTrack { String uuid; // pk /** @ejb:persist-field @ejb:relation name=songs_composer */ Musician getComposer(); } Generates ejb-relation ejb-relation-namesongs_composer/ejb-relation-name ejb-relationship-role multiplicityMany/multiplicity relationship-role-source ejb-nameCDTrack/ejb-name /relationship-role-source cmr-field cmr-field-namecomposer/cmr-field-name /cmr-field /ejb-relationship-role ejb-relationship-role multiplicityOne/multiplicity relationship-role-source ejb-nameMusician/ejb-name /relationship-role-source cmr-field cmr-field-nameCDTrack/cmr-field-name cmr-field-typejava.util.Collection/cmr-field-type /cmr-field /ejb-relationship-role /ejb-relation Tables .. Musician { String name; } CDTrack { String uuid; String composer; } Got it? So what is the problem? Table mapping is an implementation detail. Does the above not deploy? Is ejb-doclet generating bad ddl? -dain ___ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development
RE: [JBoss-dev] 1 to Many Relations
Ok stop for a second. Do you have a jbosscmp-jdbc.xml file that specifies the relationship should be mapped to a foreign key field named composer? If yes, then this is a bug. If no, then this is a suggestion. If it is a suggestion, say so, and I will consider it. My main goal when creating column names it to always allow an ejb jar to deploy without requiring a jbosscmp-jdbc.xml file. When explaining the suggestion explain why you would not get a name collision. -dain -Original Message- From: Dave Smith [mailto:[EMAIL PROTECTED]] Sent: Friday, November 16, 2001 12:22 PM To: Dain Sundstrom Cc: [EMAIL PROTECTED] Subject: Re: [JBoss-dev] 1 to Many Relations When it tries to load the CDTrack relation it generates the following sql statement .. select uuid from CDTrack where composer_composed_songs=? should be .. select uuid from CDTrack where composer=? Dain Sundstrom wrote: I'm using xdoclet to generate the ejb-jar.xml file. When you are generating the accessor methods it automaticly assumes that the accessor name matches the database column name. So in your example by default it is looking for a database columns named composer and performer. This is a packaging issue, ie how much work and how confusing is it to generate the ejb-jar.xml files. From my point of view I think that the simplist case is that each database column has a matching get/set method . So in xdoclet .. Musician { String name; // pk /** @ejb:persist-field @ejb:relation name=songs_composer */ Collection getComposedSongs(); } CDTrack { String uuid; // pk /** @ejb:persist-field @ejb:relation name=songs_composer */ Musician getComposer(); } Generates ejb-relation ejb-relation-namesongs_composer/ejb-relation-name ejb-relationship-role multiplicityMany/multiplicity relationship-role-source ejb-nameCDTrack/ejb-name /relationship-role-source cmr-field cmr-field-namecomposer/cmr-field-name /cmr-field /ejb-relationship-role ejb-relationship-role multiplicityOne/multiplicity relationship-role-source ejb-nameMusician/ejb-name /relationship-role-source cmr-field cmr-field-nameCDTrack/cmr-field-name cmr-field-typejava.util.Collection/cmr-field-type /cmr-field /ejb-relationship-role /ejb-relation Tables .. Musician { String name; } CDTrack { String uuid; String composer; } Got it? So what is the problem? Table mapping is an implementation detail. Does the above not deploy? Is ejb-doclet generating bad ddl? -dain ___ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development ___ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development
Re: [JBoss-dev] 1 to Many Relations
Finally, we are on the same page ..not even a blue moon ... Yup this is a suggestion. I agree 100% we need to avoid using jbosscmp-jdbc.xml. Ulitmately at the database level for each table there has to be a unique column name(s) that acts as a foreign key for the relation. It also can only participate in 1 relation. For a many to many relationship with a mapping table could be a problem if the field name on both sides of the relationship were the same. But I would see this as an exception not the rule. For self joins you would have to do like you do in the EJBQL and prefix the column with the table name. Not a bad idea for all relations so select uuid from CDTrack where composer=? would be select c.uuid from CDTrack as c where c.composer=? Dain Sundstrom wrote: Ok stop for a second. Do you have a jbosscmp-jdbc.xml file that specifies the relationship should be mapped to a foreign key field named composer? If yes, then this is a bug. If no, then this is a suggestion. If it is a suggestion, say so, and I will consider it. My main goal when creating column names it to always allow an ejb jar to deploy without requiring a jbosscmp-jdbc.xml file. When explaining the suggestion explain why you would not get a name collision. -dain -Original Message- From: Dave Smith [mailto:[EMAIL PROTECTED]] Sent: Friday, November 16, 2001 12:22 PM To: Dain Sundstrom Cc: [EMAIL PROTECTED] Subject: Re: [JBoss-dev] 1 to Many Relations When it tries to load the CDTrack relation it generates the following sql statement .. select uuid from CDTrack where composer_composed_songs=? should be .. select uuid from CDTrack where composer=? Dain Sundstrom wrote: I'm using xdoclet to generate the ejb-jar.xml file. When you are generating the accessor methods it automaticly assumes that the accessor name matches the database column name. So in your example by default it is looking for a database columns named composer and performer. This is a packaging issue, ie how much work and how confusing is it to generate the ejb-jar.xml files. From my point of view I think that the simplist case is that each database column has a matching get/set method . So in xdoclet .. Musician { String name; // pk /** @ejb:persist-field @ejb:relation name=songs_composer */ Collection getComposedSongs(); } CDTrack { String uuid; // pk /** @ejb:persist-field @ejb:relation name=songs_composer */ Musician getComposer(); } Generates ejb-relation ejb-relation-namesongs_composer/ejb-relation-name ejb-relationship-role multiplicityMany/multiplicity relationship-role-source ejb-nameCDTrack/ejb-name /relationship-role-source cmr-field cmr-field-namecomposer/cmr-field-name /cmr-field /ejb-relationship-role ejb-relationship-role multiplicityOne/multiplicity relationship-role-source ejb-nameMusician/ejb-name /relationship-role-source cmr-field cmr-field-nameCDTrack/cmr-field-name cmr-field-typejava.util.Collection/cmr-field-type /cmr-field /ejb-relationship-role /ejb-relation Tables .. Musician { String name; } CDTrack { String uuid; String composer; } Got it? So what is the problem? Table mapping is an implementation detail. Does the above not deploy? Is ejb-doclet generating bad ddl? -dain ___ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development ___ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development
Re: [JBoss-dev] 1 to Many Relations
You can set a different column name using @jboss:column-name (see http://xdoclet.sourceforge.net/jboss.html#column-name) cheers dim On Fri, 16 Nov 2001, Dave Smith wrote: I'm using xdoclet to generate the ejb-jar.xml file. When you are generating the accessor methods it automaticly assumes that the accessor name matches the database column name. So in your example by default it is looking for a database columns named composer and performer. This is a packaging issue, ie how much work and how confusing is it to generate the ejb-jar.xml files. From my point of view I think that the simplist case is that each database column has a matching get/set method . So in xdoclet .. Musician { String name; // pk /** @ejb:persist-field @ejb:relation name=songs_composer */ Collection getComposedSongs(); } CDTrack { String uuid; // pk /** @ejb:persist-field @ejb:relation name=songs_composer */ Musician getComposer(); } Generates ejb-relation ejb-relation-namesongs_composer/ejb-relation-name ejb-relationship-role multiplicityMany/multiplicity relationship-role-source ejb-nameCDTrack/ejb-name /relationship-role-source cmr-field cmr-field-namecomposer/cmr-field-name /cmr-field /ejb-relationship-role ejb-relationship-role multiplicityOne/multiplicity relationship-role-source ejb-nameMusician/ejb-name /relationship-role-source cmr-field cmr-field-nameCDTrack/cmr-field-name cmr-field-typejava.util.Collection/cmr-field-type /cmr-field /ejb-relationship-role /ejb-relation Tables .. Musician { String name; } CDTrack { String uuid; String composer; } Got it? Dain Sundstrom wrote: Dain Sundstrom wrote: OK i'm playing with the latest RH CVS and testing out 1 to many relations (bi directional). So .. Table1 { primary_key int, } TableMany { primary_key int, table1_key int, } class Table1 { int getPrimary_key() Collection getTableMany(); } class TableMany { int getPrimary_key(); int getTable1_key(); } the problem is that when it tries to fetch TableMany it looks for a field called table1_key_primary_key. It would seem that the default key should not be made up but the foreign key of the other side of the relationship. So line 80 of JDBCRelationshipRoleMetaData.java should just be tempCmrFieldName = relatedRole.getEntityName(); 1. Defaults can be overridden. This is the default case. The strange cases should be overridden. Read Marc's bit about packaging. What bit about packaging? 2. What happens when you have two one-to-many relationships between Table1 and TableMany? Doesn't matter you still need Table1's primary key in TableMany. So you would have Table1 { Collection getTableMany(); Collectiont getTableMany2(); } TableMany { int getTable1_key(); int getTable2_2_key(); } You have lost me. What is the problem? Let us clean up the example: Musician { String name; // pk Collection getComposedSongs(); Collection getPreformedSongs(); } CDTrack { String uuid; // pk Musician getComposer(); Musician getPerformer(); } You would get the following table: Musician { name } CDTrack { uuid, musician_composer_name, musician_performer_name } As you can see you get fk with the following pattern: related_entity_name_cmr_field_name_related_entity_pk_field_name unless the many side does not have a cmr field for the relationshiop then you get: related_entity_name_related_cmr_field_name_related_entity_pk_field_name Or am I answering the wrong question? -dain ___ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development ___ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development
Re: [JBoss-dev] 1 to Many Relations
ok - sorry... cheers dim On Fri, 16 Nov 2001, Dave Smith wrote: I know. The point is as far as I am concered this is the most basic of cases. We want to avoid users having to know jboss'isms unless they are doing something quite weird. Dmitri Colebatch wrote: You can set a different column name using @jboss:column-name (see http://xdoclet.sourceforge.net/jboss.html#column-name) cheers dim ___ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development
RE: [JBoss-dev] 1 to Many Relations
OK i'm playing with the latest RH CVS and testing out 1 to many relations (bi directional). So .. Table1 { primary_key int, } TableMany { primary_key int, table1_key int, } class Table1 { int getPrimary_key() Collection getTableMany(); } class TableMany { int getPrimary_key(); int getTable1_key(); } the problem is that when it tries to fetch TableMany it looks for a field called table1_key_primary_key. It would seem that the default key should not be made up but the foreign key of the other side of the relationship. So line 80 of JDBCRelationshipRoleMetaData.java should just be tempCmrFieldName = relatedRole.getEntityName(); 1. Defaults can be overridden. 2. What happens when you have two one-to-many relationships between Table1 and TableMany? -dain ___ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development