You are trying to use uknown and 'known' primary keys at the same time. You must use either one. Just remove unknown-pk.
Yes, you need to use jdbc-type/sql-type in key-field.


Ivens Porto wrote:

Alexey Loubyansky wrote:

Yes, it should. It is not yet clear for me how the fk field accord to be
non-null. All fk fields allow null values by default. Perhaps, it came
from sql-type? Could you, please, post the declaration of the unknown pk
from your DDs?


Below is the declaration of my entity bean (it is generated by xdoclet):

      <entity>
         <ejb-name>MovieDayOfWeekSchedule</ejb-name>
         <table-name>t_movie_day_of_week_schedule</table-name>

         <cmp-field>
            <field-name>id</field-name>

            <jdbc-type>INTEGER</jdbc-type>
            <sql-type>SERIAL</sql-type>

            <auto-increment/>
        </cmp-field>
         <cmp-field>
            <field-name>startDay</field-name>

        </cmp-field>
         <cmp-field>
            <field-name>endDay</field-name>

        </cmp-field>
         <cmp-field>
            <field-name>startDayIntValue</field-name>

        </cmp-field>
         <cmp-field>
            <field-name>endDayIntValue</field-name>

</cmp-field>

    <unknown-pk>
        <unknown-pk-class>java.lang.Integer</unknown-pk-class>
        <jdbc-type>INTEGER</jdbc-type>
        <sql-type>SERIAL</sql-type>
        <auto-increment/>
    </unknown-pk>
    <entity-command name="postgresql-fetch-seq">
    </entity-command>
  </entity>

I found a solution to avoid creating the fk as not null: just add
<jdbc-type>INTEGER</jdbc-type> and <sql-type>INTEGER</sql-type> in the
<keyfield> for the bean relationship. After this JBoss created the fk
field just as INTEGER.

But then another problem, xdoclet does not support specifing the
<jdbc-type> and <sql-type> in the tag @jboss.relation. Has any one
hacked the jboss templates in xdoclet to handle this?


Ivens Porto wrote:


Alexey Loubyansky wrote:


It works for me.

  public abstract Integer getIntegerField();
  public abstract void setIntegerField(Integer value);

  public abstract int getIntField();
  public abstract void setIntField(int value);

12:30:34,262 DEBUG [Child] Executing SQL: CREATE TABLE CHILD(CHILD_ID
BIGINT NOT NULL, name VARCHAR(250) BINARY, integerField INTEGER,
intField INTEGER NOT NULL, PARENT_FK BIGINT, CONSTRAINT pk_CHILD PRIMARY
KEY (CHILD_ID))

Do you have a testcase?



Thanks to other posts I now see the reason for setting int fields as not
null.

After digging a bit more I found that actually the problem I'm having is
bit different.


I have a 1->N bidirectional relation.


On the 1 side of the relation the pk field is an unknown pk with
auto-increment. With Postgresql JBoss correctly uses the type SERIAL for
this pk field. This pk is used as a fk on the N side of the relation.

So, when JBoss creates the table for N side of the relation is adds a
column for the fk, and the type for the fk column is the same type used
on the 1 side of the relation, in this case: SERIAL.

The problem is that on the N side of the relation I have some beans that
are not associated with any bean on the 1 side. Then when I create a
bean on the N side, without an associated bean on the 1 side, I got an
exception telling me that JBoss cannot insert a null value on the fk
column.

This happens because the type of the fk field is SERIAL, the same type
used as the pk on the 1 side of the relation, that in Postgresql is of
type:

"integer | not null default
nextval('public.t_movie_day_of_week_schedule_movieid_seq'::text)"

My question then is: when a pk field is of type unknown with
auto-increment and it's used as a fk field in a relation, shouldn't the
fk colunm type be just INTEGER instead of SERIAL?




Thanks,

alex

Ivens Porto wrote:



Hi,

I'm using JBoss 3.2.2 and PostgreSQL 7.3.4.

JBoss is doing something that I can't figure out why.

In my CMP beans, JBoss always use the constraint NOT NULL for fields of
type integer, even thought I don't set the <not-null/> property in
jbosscmp-jdbc.xml for the fields.

If the persistent field in the CMP bean is of type int or Integer, JBoss
creates the database table with the constraint NOT NULL for integer type
fields.

Does anyone knows why JBoss does this?

-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive?  Does it
help you create better code?   SHARE THE LOVE, and help us help
YOU!  Click Here: http://sourceforge.net/donate/
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user






-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive?  Does it
help you create better code?   SHARE THE LOVE, and help us help
YOU!  Click Here: http://sourceforge.net/donate/
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to