-
1. Re: Attempt to get lock ref with a null object
jdijkmeijer Nov 4, 2003 3:51 PM (in response to jdijkmeijer)Yeah I found it..
I use auto increment fields in mysql. So I create an ejb in cmp, the cmp creates a record in db and everybody is happy, right? Not everybody, as soon as you do some modification on the newly created bean the pk is still missing in the bean. The cmp is not loading the db pk in and so this is still null. Hence the error messag.
Solutions:
http://www.kylev.com/projects/jboss/cmpauto.html
with xdoclet the link above can be summarized as:
* @jboss.unknown-pk
* sql-type="INTEGER"
* jdbc-type="INTEGER"
* auto-increment="true"
* class="Integer"
* column-name="roleid"
* field-name="roleId"
* readonly="true"
* @jboss.entity-command
* name="mysql-get-generated-keys"
I think this is platform and db dependent. So in terms of portability maybe not the wisest choice.
solution 2 get rid of the autoincrement fields in db design, make an extra db table, with entity beannames and generate keys and whenever you do a create call this cmp (via a session or local and retrieve the value + 1), and have the db update the key for the corresponding value. DB and appserver independent.
I hope that both methods are cluster and thread save.
jeroen -
2. Re: Attempt to get lock ref with a null object
jdijkmeijer Nov 12, 2003 2:21 AM (in response to jdijkmeijer)In fact the auto-gen-key option is not working..
After creation retrieval of the pk-field results in a class cast exception. java.lang.Long vs java.lang.Integer (as it is supposed to be). I havent been able to figure why this went wrong: The field representing the pk field goes nuts after querying, so the only thing remaining is this keygen table.