Bugs item #850859, was opened at 2003-11-28 21:34
Message generated for change (Comment added) made by loubyansky
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=376685&aid=850859&group_id=22866

Category: JBossCMP
Group: v3.2
>Status: Closed
>Resolution: Invalid
Priority: 5
Submitted By: Sandro Santos Andrade (sandros)
Assigned to: Alexey Loubyansky (loubyansky)
Summary: CMP-Engine changing primary-key field value ???

Initial Comment:

Hi all,

I have two entities 'SystemUser' (primary key 'login')
and 'Author', where author's primary-key is composed by
an foreign-key to systemuser's primary-key and a string
field fullName.
I create in author a field that is both cmp-field and
cmr-field and did all relationship configurations.
All table were successfully created with primary-key
and foreign-key constraints (PostgreSQL):

Table "public.systemuser"
Column | Type | Modifiers
----------+------+-----------
login | text | not null
fullname | text | not null
password | text | not null
Indexes: pk_systemuser primary key btree (login)

Table "public.author"
Column | Type | Modifiers
----------+------+-----------
login | text | not null
fullname | text | not null
name | text | not null
address | text | not null
Indexes: pk_author primary key btree (login, fullname)
Foreign Key constraints: fk_author_login FOREIGN KEY
(login) REFERENCES systemuser(login) ON UPDATE NO
ACTION ON DELETE NO ACTION

But, the accessor setLogin(x), where x is the
LocalInterface for systemuser with primary-key =
'sandros', in entity Author throws the following error:
"Could not create entity:java.sql.SQLException: ERROR:
fk_author_login referential integrity violation - key
referenced from author not found in systemuser", but
record 'sandros' exists in systemuser table.

If I delete the constraint fk_author_login in table
author, the record inserted is:

login | fullname | name | address
--------------------------+-----------------------+----------------+---------
local/SystemUser:sandros | Sandro Santos Andrade |
Andrade, S. S. | UFBa

That is, the systemuser's primary key (login) is being
'local/SystemUser:sandros' rather than just 'sandros'

If the cmr-field login is not part of primary key the
insert occurs all right.

Any idea ? I'm using jboss 3.2.2rc2, jdk 1.4.2 in
Debian kernel 2.4.18 and postgresql 7.3.4.

Thanks in advance,

Sandro


----------------------------------------------------------------------

>Comment By: Alexey Loubyansky (loubyansky)
Date: 2003-12-01 16:36

Message:
Logged In: YES 
user_id=543482

Because you declared a CMR field as a CMP field. CMR can't
be CMP and CMP can't be CMR. If you have questions, please,
ask them in jboss-user mailing list or forums on jboss.org

----------------------------------------------------------------------

Comment By: Sandro Santos Andrade (sandros)
Date: 2003-12-01 14:55

Message:
Logged In: YES 
user_id=747271

loubyansky,

I have just the CMR acessors:

// CMR
public abstract SystemUserLocal getLogin();
public abstract void setLogin(SystemUserLocal user);

but I also declared 'login' as a cmp-field in ejb-jar.xml.
The code was compiled and table were created as expected.

The question is: why was the prefix 'local/SystemUser:'
included in foreign key ?

Thanks,


----------------------------------------------------------------------

Comment By: Alexey Loubyansky (loubyansky)
Date: 2003-11-28 22:26

Message:
Logged In: YES 
user_id=543482

Each field whether it is CMP or CMR must have abstract
getter and setter in the bean class.
In your case, it would be like:

//CMP
public abstract String getLogin();
public abstract void setLogin(String user);
// CMR
public abstract SystemUserLocal getLogin();
public abstract void setLogin(SystemUserLocal user);

Which won't be compiled. I guess, you have only the CMP
getter and setter and declare it as both CMP and CMR in the
ejb-jar.xml. Is it correct?

----------------------------------------------------------------------

Comment By: Sandro Santos Andrade (sandros)
Date: 2003-11-28 22:07

Message:
Logged In: YES 
user_id=747271


loubyansky,

You are right. I have CMP and CMR fields with the same name
(login). It was the way I found to insert an CMR-field in
the primary key of entity 'Author'. The bean classes were
successfully compiled and database tables perfectly created.
In entity Author, the primary key is composed: a CMR-field
(login) and a CMP-field (fullName).

What do you mean for: "You can have a foreign key of a cmr
field mapped to a primary key field but not cmr itself" ???

I could alter the toString method in order to supress to
'local/SystemUser:' prefix !

Sandro


----------------------------------------------------------------------

Comment By: Alexey Loubyansky (loubyansky)
Date: 2003-11-28 21:53

Message:
Logged In: YES 
user_id=543482

The result inserted is the result of EJBLocalObject.toString().
It looks like there is a CMP and a CMR fields with the same
name which is impossible (following the spec) because you
would not be able to compile the bean class.
Are you declaring a cmp-field as a cmr-field in ejb-jar.xml?
You can have a foreign key of a cmr field mapped to a
primary key field but not cmr itself.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=376685&aid=850859&group_id=22866


-------------------------------------------------------
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-Development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to