jboss3.0.0beta, jdk1.3.1_02, MySQL

Two questions:

1. I understand that for CMR fields you set them in ejbPostCreate, but what
if your table (that already exists) has these fields marked as "NOT NULL"?
The initial INSERT INTO fails since it has that field as NULL and it never
gets to ejbPostCreate.

2. In my case I have control of the DB layout, so I removed the NOT NULL
from the initial creation of the table to see it work (and added in checks
for null objects? is this the best way to do this?). I then get the
following error:

java.lang.Error: id may not be null
        at org.jboss.ejb.CacheKey.<init>(CacheKey.java:80)
        at
org.jboss.ejb.plugins.EntityInstanceCache.createCacheKey(EntityInstanceCache
.java:63)
        at
org.jboss.ejb.plugins.CMPPersistenceManager.createEntity(CMPPersistenceManag
er.java:239)
        at
org.jboss.ejb.EntityContainer.createLocalHome(EntityContainer.java:561)
        at java.lang.reflect.Method.invoke(Native Method)
        at
org.jboss.ejb.EntityContainer$ContainerInterceptor.invokeHome(EntityContaine
r.java:1051)
        at
org.jboss.ejb.plugins.AbstractInterceptor.invokeHome(AbstractInterceptor.jav
a:73)
        at
org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invokeHome(EntitySync
hronizationInterceptor.java:222)
        at
org.jboss.ejb.plugins.EntityInstanceInterceptor.invokeHome(EntityInstanceInt
erceptor.java:136)
        at
org.jboss.ejb.plugins.EntityLockInterceptor.invokeHome(EntityLockInterceptor
.java:80)
        at
org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor
.java:98)
        at
org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.
java:167)
        at
org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome(TxInterceptorCMT.java:52)
        at
org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(SecurityInterceptor.jav
a:102)
        at
org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:109)
        at
org.jboss.ejb.EntityContainer.invokeHome(EntityContainer.java:469)
        at
org.jboss.ejb.plugins.local.BaseLocalContainerInvoker.invokeHome(BaseLocalCo
ntainerInvoker.java:244)
        at
org.jboss.ejb.plugins.local.BaseLocalContainerInvoker$HomeProxy.invoke(BaseL
ocalContainerInvoker.java:369)
        at $Proxy13.create(Unknown Source)
        at
test.com.acs.j2ee.framework.user.entity.UserRoleEntityTest.testCreate(Unknow
n Source)

My code looks like this:

   public String ejbCreate(UserEntity user, RoleEntity role, GroupEntity
group)
   {
      setId(new Integer(0)); // Auto increment
      return null;
   }
   
   public void ejbPostCreate(UserEntity user, RoleEntity role, GroupEntity
group)
   {
      setUser(user);
      setRole(role);
      setGroup(group);
   }

where UserEntity, RoleEntity, and GroupEntity are all foriegn-key
relationships.

In the database, the initial INSERT INTO worked:

mysql> select * from userroles;
+----+----------+----------+---------+
| id | username | roleName | groupId |
+----+----------+----------+---------+
|  7 | NULL     | NULL     |    NULL |
+----+----------+----------+---------+

But that "7" isn't making it back to the EJB. Should I not be using the
"AUTO INCREMENT" feature of MySQL to make sure I get unique primary keys? My
DB create statment is:

CREATE TABLE IF NOT EXISTS UserRoles(
   id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY, 
   username VARCHAR(32),
   roleName VARCHAR(64), 
   groupId INTEGER
)

Jason

p.s. In the JBoss Forums, do a 'search all forums' for "relationship
ejbPostCreate". For me, at least, I get 272 results, but only number one is
shown then there is a "2" and that's the end of the page.


_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to