From: Ivens P. <iv...@os...> - 2003-10-31 17:28:30
|
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? > Doing more tests I came to a situation that I cannot get out. When creating a bean on the N side of the relation I'm getting the exception: java.sql.SQLException: ERROR: ExecInsert: Fail to add null value in not null attribute movieid This is expected, as the fk field is of type SERIAL, that in Postgresql is has modifier "not null", and the fk field is only set after ejbPostCreate(). Then I configured the container with <insert-after-ejb-post-create> to true, but then when I create a bean on the N side of the relation and set it's relation with the 1 side on ejbPostCreate(), I get the following exception: 14:20:42,391 ERROR [STDERR] javax.ejb.CreateException: Primary key for created instance is null. Can anyone tell me what should I do??? > > 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? > > > > -- > _/_/_/ _/_/_/ _/_/_/ > Ivens Porto _/ _/ _/ _/ > OSE - Open Systems Engineering _/ _/ _/ _/ > http://www.ose.com.br _/ _/ _/_/_/ _/_/_/_/ > Phone: (55) 34 - 3214-5995 _/ _/ _/ _/ > Fax: (55) 34 - 3214-5994 _/ _/ _/ _/ > _/_/_/ _/_/_/ _/_/_/ -- _/_/_/ _/_/_/ _/_/_/ Ivens Porto _/ _/ _/ _/ OSE - Open Systems Engineering _/ _/ _/ _/ http://www.ose.com.br _/ _/ _/_/_/ _/_/_/_/ Phone: (55) 34 - 3214-5995 _/ _/ _/ _/ Fax: (55) 34 - 3214-5994 _/ _/ _/ _/ _/_/_/ _/_/_/ _/_/_/ |