• Post Reply Bookmark Topic Watch Topic
  • New Topic

CMP EJB's and Autonumber Field Problem  RSS feed

 
Karl Laird
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a SQL Server Database with 'autonumber' fields as the primary keys. As the container is responsible for the generation of all SQL code and create methods of the bean I cannot figure out how to create a new bean.
The autonumber field will not accept a placeholder number (and so I cannot just enter another number) and being of int type null is not a valid parameter.
If anyone could help on what I have to do to get the create() methods to work where the PK is autogenerated in a CMP Bean? I can get it to work in a Bean managed environment because I can customise the SQl - but how does it work under CMP?
Thanking you kindly
Karl
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this is something that people are still trying to resolve. CMP expects the container to do all the work, not have the DBMS step in. Technically, CMP shouldn't expect such things, because the theoretical persistence for EJBs doesn't even have to BE a DBMS, much less one that supports auto-generated keys (or even indexes of any kind). However, I expect that at some point there will be a concession to practical needs.
Short-term, though, you have a problem, since the create() function is supplied with a blank bean and there's no way to "look ahead" and get the data you need for the key.
 
Karl Laird
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Finally got this to work!! In the properties for the datastore the 'dialect' must be set to mssqlserver, and the 'primarykeydeclaration' property must be set to null. Then everything works as it should!!!
Thanks,
Karl
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!