• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Entity RelationShip (CMP)

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've 2 cmps one for a master table(main EJB) and one for transaction table(sub EJB) I'm getting problem while adding data into transaction table..In master table ValueCode is the Primary key. There is a set method for valueCode in SubEJB , it is taking an object of main EJB as parameter. Before creating sub ejb object, i'm creating a mainEJB object nd passing it to create() in subEJB.
The error : (here AllowValuesEJB - main , AllowValuesSubEJB - sub)

java.lang.IllegalStateException: getEJBLocalObject not allowed or not successful [1]
at com.evermind.server.ejb.AbstractEJBContext.getEJBLocalObject(AbstractEJBContext.java:77)
at AllowValuesSubEJBBean_PersistenceManager3.__core__setallowValuesEJB_value_code(AllowValuesSubEJBBean_PersistenceManager3.java:133)
at AllowValuesSubEJBBean_PersistenceManager3.setAllowValuesEJB_value_code(AllowValuesSubEJBBean_PersistenceManager3.java:156)
at mypackage4.impl.AllowValuesSubEJBBean.ejbCreate(AllowValuesSubEJBBean.java:22)
at AllowValuesSubEJBLocalHome_EntityHomeWrapper9.create(AllowValuesSubEJBLocalHome_EntityHomeWrapper9.java:802)
at mypackage4.impl.MySessionEJBBean.CreateValues(MySessionEJBBean.java:36)
at MySessionEJB_StatelessSessionBeanWrapper4.CreateValues(MySessionEJB_StatelessSessionBeanWrapper4.java:98)
at java.lang.reflect.Method.invoke(Native Method)
at com.evermind.server.rmi.RMICallHandler.run(RMICallHandler.java:119)
at com.evermind.server.rmi.RMICallHandler.run(RMICallHandler.java:48)
at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:803)
at java.lang.Thread.run(Thread.java:484)

plz help me ...
 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well if you have two beans in a 1(beanA)-to-N(beanB) relationship, the process should be this:
When creating beanA, beanB should already exist. So, creating beanA goes like this:
ejbCreate(....., BeanBLocal beanB){ //all the necessary parameters for
//ejbCreate
setXXX(...);//set the properties
setXXX(...);
}
ejbPostCreate(....., BeanBLocal beanB){ //the same signature as ejbCreate()
setBeanB(beanB);//set the relationship
}
This is the right procedure to save a bean in 1-to-N relationship with another bean.

Hope this helps.
 
Nitha Ramachandran
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oops..
again while creating it is throwing error like cannot insert null into that field. I'm getting the object of beanB using a findByPrimaryKey() before calling create method.. i've tested the bean object, itz not null, so instead of postcreate() i;ve to give in create() itself know? or ny other way ?
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Nitha Ramachandran:
again while creating it is throwing error like cannot insert null into that field. I'm getting the object of beanB using a findByPrimaryKey() before calling create method.. i've tested the bean object, itz not null, so instead of postcreate() i;ve to give in create() itself know? or ny other way ?


You have a couple of options.
- If your container supports it, set it to do the insert *after* ejbPostCreate.
- You can change the DB to allow the foreign key to be null.
You cannot set relationships in ejbCreate, so that's just not an option (the bean you're creating doesn't have a PK to relate to).
reply
    Bookmark Topic Watch Topic
  • New Topic