I notice you are not specifying an idmethod attribute on your tables,
are you specifying a default. I suspect not as then you would probably
have the attribute on your ARTIST_HAS_WEBSITE table.
Use idmethod="native" or idmethod="autoincrement", if native does not
work, on tables that have generated pk's. And then use idmethod="none"
on tables such as ARTIST_HAS_WEBSITE.
john mcnally
Fabian Moerchen wrote:
>
> here's (part of) my schema. did i do something wrong?
> could very well be since it's my first. ;)
>
> <table name="GENRE">
> <column name="ID" type="INTEGER" required="true"
> autoIncrement="true" primaryKey="true"/>
> <column name="NAME" type="VARCHAR" size="50" required="true"/>
> <unique>
> <unique-column name="NAME"/>
> </unique>
> </table>
> <table name="ARTIST">
> <column name="ID" type="INTEGER" required="true"
> autoIncrement="true" primaryKey="true"/>
> <column name="NAME" type="VARCHAR" size="100" required="true"/>
> <column name="PATTERN" type="VARCHAR" size="255"/>
> <column name="SORTNAME" type="VARCHAR" size="255"/>
> <column name="GENRE_ID" type="INTEGER"/>
> <foreign-key foreignTable="GENRE">
> <reference local="GENRE_ID" foreign="ID"/>
> </foreign-key>
> </table>
> <table name="WEBSITE">
> <column name="ID" type="INTEGER" required="true"
> autoIncrement="true" primaryKey="true"/>
> <column name="NAME" type="VARCHAR" size="100" required="true"/>
> <column name="URL" type="VARCHAR" size="200" required="true"/>
> </table>
> <table name="ARTIST_HAS_WEBSITE">
> <column name="ARTIST_ID" type="INTEGER" required="true"
> primaryKey="true"/>
> <foreign-key foreignTable="ARTIST">
> <reference local="ARTIST_ID" foreign="ID"/>
> </foreign-key>
> <column name="WEBSITE_ID" type="INTEGER" required="true"
> primaryKey="true"/>
> <foreign-key foreignTable="WEBSITE">
> <reference local="WEBSITE_ID" foreign="ID"/>
> </foreign-key>
> </table>
>
> bye
> fabian
>
> On Thu, 2002-01-24 at 07:28, John McNally wrote:
> > The first example should work. You might want to show your schema.xml,
> > to give others some idea what might be wrong. artist1.getPrimaryKey()
> > should give the id assigned after saving the object. It should not be
> > null. If it is something is wrong with your xml.
> >
> > john mcnally
> >
> > >
> > > this doesn't work:
> > >
> > > Artist artist1 = new Artist();
> > > artist1.setName("Primus");
> > > artist1.save();
> > >
> > > Website website1 = new Website();
> > > website1.setName("Primus Online");
> > > website1.setUrl("http://www.primussucks.com");
> > > website1.save();
> > >
> > > ArtistHasWebsite link = new ArtistHasWebsite();
> > > link.setArtist(artist1);
> > > link.setWebsite(website1);
> > > link.save(); //Column 'ARTIST_ID' cannot be null
> > >
> > > this does work:
> > >
> > > Artist artist1 = new Artist();
> > > artist1.setName("Primus");
> > > artist1.save();
> > >
> > > Website website1 = new Website();
> > > website1.setName("Primus Online");
> > > website1.setUrl("http://www.primussucks.com");
> > > website1.save();
> > >
> > > Artist artist2 = ArtistFactory.findByName(artist1.getName());
> > > Website website2 = WebsiteFactory.findByUrl(website1.getUrl());
> > >
> > > ArtistHasWebsite link = new ArtistHasWebsite();
> > > link.setArtist(artist2);
> > > link.setWebsite(website2);
> > > link.save();
> > >
> > > tried defaultIdMethod native and idBroker by now.
> > >
> > > bye
> > > fabian
> > >
> > > --
> > > To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
> > > For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
> >
> > --
> > To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
> > For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
> >
> >
>
> --
> To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>