This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Creating entity beans with auto numbered primary key  RSS feed

 
Adrian Bates
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have two entity bean with a CMR between them. I am successfully creating the first one but when I try and create the child entity bean I get a NullPointerException.

Now I think this is because the gernerated code tries to get the primary key of the created entity bean and this is not set as it is set using a auto number in the database (An oracle sequence and trigger).

Is there anyway i can get round this problem?

This is the auto generated code:

public dmd.sync.ejbs.entity.AppliancePackInfoLocal create_Local(dmd.sync.dataobjects.dto.AppliancePackInfoDTO appliancePackInfoDTO, dmd.sync.ejbs.entity.AmppLocal amppLocal) throws javax.ejb.CreateException, java.rmi.RemoteException {

BeanO beanO = null;
dmd.sync.ejbs.entity.AppliancePackInfoLocal result = null;
boolean createFailed = false;
boolean preCreateFlag = false;

try {
beanO = super.createBeanO();
dmd.sync.ejbs.entity.AppliancePackInfoBean bean = (dmd.sync.ejbs.entity.AppliancePackInfoBean) beanO.getEnterpriseBean();
preCreateFlag = super.preEjbCreate(beanO);
bean.ejbCreate(appliancePackInfoDTO, amppLocal);
Object ejsKey = keyFromBean(bean);
result = (dmd.sync.ejbs.entity.AppliancePackInfoLocal) super.postCreate_Local(beanO, ejsKey, true);
bean.ejbPostCreate(appliancePackInfoDTO, amppLocal);
super.afterPostCreate(beanO, ejsKey);
}


It must be falling over on the last line as it calls the bean.ejbPostCreate fine.


Thanks in advance,
Adrian
 
Adrian Bates
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I seem to have found a fudge that gets round this problem. By setting the key to some unique value the problem is avoided. This value is then overwritten by the trigger on the database.

Whats really strange is that it appear to have to be unique across all entity beans that I creat in a single transaction even if they are of different types.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!