| Author |
Foreign key column
|
Pinal N Patel
Ranch Hand
Joined: Sep 05, 2003
Posts: 57
|
|
Hello Everyone, I am trying to update a row on table A which has a foreign key columns. To update, first I call findbyprimarykey() method which returns a remote interface. After receiving the remote interface, I call setter methods for columns that needs to be updated, but for strange reason (or lack of knowledge) the foreign key columns does not get updated. It works if I remove the foreign key constraint from the table. I appreciate all of your input in advance. The beans are created in EJB 2.0 in WSAD 5.0. EJB to RDB mappings are defined appropriately. Regards, Pinal
|
 |
kieranct kieranct
Greenhorn
Joined: Dec 30, 2003
Posts: 2
|
|
I have the same problem, I have created a session bean which calls an entity beans local interface, i then call several setter methods which work fine. Then i call get another entity via findbyprimarykey which works ok but when i try and call setter method passing this remote interface it collapses returning: javax.ejb.TransactionRolledbackLocalException: null; CausedByException is: null; CausedByException is: null; CausedByException is: null in the command prompt and server log says: 2003-12-30 20:06:11,201 ERROR [org.jboss.ejb.plugins.LogInterceptor] TransactionRolledbackLocalException, causedBy: java.lang.ClassCastException at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge.setInstanceValue(JDBCCMRFieldBridge.java:662) blah blah blah Here is the session bean code: public String setValues(String id, Integer qual, Double buy, Double sell, String title, String genre, String redition, String rsupplier){ try{ LocalCopyHome home = (LocalCopyHome)jndiContext.lookup("local/CopyEJB"); LocalCopy copy = home.create(id); //need to implement properly copy.setQuality(qual); //need to implement properly copy.setBuyinprice(buy); copy.setSelloutprice(sell); //bookid? copy.setTitle(title); copy.setGenre(genre); Object ref1 = jndiContext.lookup("x0150436/SupplierEJB"); Object ref2 = jndiContext.lookup("x0150436/EditionEJB"); RemoteSupplierHome shome = (RemoteSupplierHome) PortableRemoteObject.narrow (ref1, RemoteSupplierHome.class); RemoteEditionHome ehome = (RemoteEditionHome) PortableRemoteObject.narrow (ref2, RemoteEditionHome.class); RemoteSupplier supp = shome.findByPrimaryKey(rsupplier); RemoteEdition ed = ehome.findByPrimaryKey(redition); copy.setEdition(ed.getEditionid()); copy.setSupplier(supp.getSupplierid()); return "success"; } catch (Throwable t){return t.toString();} } im using jboss with a postgresql database, just on a side note if i go into psql and insert a valid (fk constraint) string value corresponding to an editionid or supplierid respectively it likes it!? i think the problem is that the server is trying to put a remote interface object into what is a string value in postgresql (hence classcastexception in logs) but i have jack all idea how to fix / hack around it as in ejb-jar.xml relationship fields can only be one or a collection/set of remoteinterfaces (i think...) any ideas anyone? cheers kieran ct
|
 |
kieranct kieranct
Greenhorn
Joined: Dec 30, 2003
Posts: 2
|
|
i read this article http://www.devx.com/opensource/Article/17663/0/page/1 and think i figured out the problem, you need to get and set with local interfaces rather then remote interfaces, i think.... i looked at his source code and completely restarted and it worked so above is a guess based on the difference between them, good luck
|
 |
Kyle Brown
author
Ranch Hand
Joined: Aug 10, 2001
Posts: 3879
|
|
FYI, you're right -- we only manage CMR relationships with local getters/setters as per the way the EJB Specification dictates. Kyle
|
Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
|
 |
shyam jakki
Ranch Hand
Joined: Dec 09, 2003
Posts: 37
|
|
HI As per the foreign key column is concerned u have to use local interfaces so that we manage CMR relationships with local getters/setters.For the CMR fields u have to use the local interfaces.If u use local interfaces, i think u may not have this problem. Regards shyam
|
 |
 |
|
|
subject: Foreign key column
|
|
|