Hello,

Sorry to answer my own question, but I found out that it was my fault, well sort of...

In JBoss-3.0.0RC2 I tried to use this kind of ejbCreate() signature (CMP 2.0):

public Interger ejbCreate(PersonValueObject person) {
    setId(person.getId());
    setName(person.getName());
    return null;
}

public void ejbPostCreate(PersonValueObject person) {
    TaskLocal taskLocal = 
TaskUtil.getLocalHome().findByPrimaryKey(person.getTask().getId());
    setTask(taskLocal);
}

But foreing keys were not populated.

(person.getTask() returns a TaskValueObject object)

I am very sure that person.getTask() returned the correct TaskValueObject, with 
correct id, etc.
After Jboss called ejbPostCreate(), I printed the personLocal.getTask().getId() value 
(from the Person Entity Bean just created), and it shows the correct number, but the 
database foreign key (task_id in my "person" table) was never populated!

It results that I should call the ejbCreate method with THIS signature to make it work:

public Interger ejbCreate(Integer id, String name, TaskLocal taskLocal) {
    setId(id);
    setName(name);
    return null
}

public void ejbPostCreate(Integer id, String name, TaskLocal taskLocal) {
    setTask(taskLocal);
}

Since I'm using Session Beans to wrap the create() method, I look for taskLocal in the 
Session Bean first, and then send it as a parameter of the create() method of the 
Person entity bean.  It works.

Does any body know why it doesn't work when I send value Objects instead of local 
objects?
I thought that "loading" the local object used _inside_ ejbPostCreate() was enough.
Maybe I should read the EJB spec again.

Thanks in advance.

Ricardo Arguello

----- Original Message ----- 
From: "Ricardo Argüello" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, May 05, 2002 3:40 AM
Subject: [JBoss-user] Entity EJB foreign key not populated


I have exactly the same problem that is described in this bug entry using, JBoss 
3.0.0RC2:

[ 549415 ] Error create Entity EJB with foreign key:
http://sourceforge.net/tracker/index.php?func=detail&aid=549415&group_id=22866&atid=376685

When I try to create an entity bean with related entity beans (CMR), I don't get any 
exception, but in the database foreign keys are not being populated.

This used to work before (I dont remember if it was on beta1 or beta2).

Reading the log/server.log file, I found something very strange:
-----------------------------------
2002-05-05 02:59:44,062 INFO [charlie.ejb.TareaBean] In ejbCreate(Tarea) ****
2002-05-05 02:59:44,064 DEBUG 
[org.jboss.ejb.plugins.cmp.jdbc.JDBCCreateEntityCommand.Tarea] Create: pk=2193
2002-05-05 02:59:44,064 DEBUG 
[org.jboss.ejb.plugins.cmp.jdbc.JDBCCreateEntityCommand.Tarea] Executing SQL: SELECT 
COUNT(*) FROM tareas WHERE id=?
2002-05-05 02:59:44,074 DEBUG 
[org.jboss.ejb.plugins.cmp.jdbc.JDBCCreateEntityCommand.Tarea] Executing SQL: INSERT 
INTO tareas (id, nombre, descripcion, horas, fecha_ingreso, empleado_id, actividad_id, 
proyecto_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
2002-05-05 02:59:44,084 DEBUG 
[org.jboss.ejb.plugins.cmp.jdbc.JDBCCreateEntityCommand.Tarea] Create: Rows affected = 
1
2002-05-05 02:59:44,084 INFO [charlie.ejb.TareaBean] In ejbPostCreate(Tarea) ****
2002-05-05 02:59:44,134 DEBUG 
[org.jboss.ejb.plugins.cmp.jdbc.JDBCFindByPrimaryKeyQuery.Proyecto.findByPrimaryKey] 
Executing SQL: SELECT id FROM proyectos WHERE id=?
2002-05-05 02:59:44,144 DEBUG 
[org.jboss.ejb.plugins.cmp.jdbc.JDBCLoadEntityCommand.Proyecto] Executing SQL: SELECT 
nombre, descripcion, empleado_id, cliente_id FROM proyectos WHERE (id=?)
2002-05-05 02:59:44,154 DEBUG 
[org.jboss.ejb.plugins.cmp.jdbc.JDBCLoadRelationCommand.Proyecto] Executing SQL: 
SELECT id FROM tareas WHERE (proyecto_id=?)
2002-05-05 02:59:44,164 DEBUG 
[org.jboss.ejb.plugins.cmp.jdbc.JDBCFindByPrimaryKeyQuery.Empleado.findByPrimaryKey] 
Executing SQL: SELECT id FROM empleados WHERE id=?
2002-05-05 02:59:44,174 DEBUG 
[org.jboss.ejb.plugins.cmp.jdbc.JDBCLoadEntityCommand.Empleado] Executing SQL: SELECT 
login, password, nombre, apellido, email FROM empleados WHERE (id=?)
2002-05-05 02:59:44,194 DEBUG 
[org.jboss.ejb.plugins.cmp.jdbc.JDBCLoadRelationCommand.Empleado] Executing SQL: 
SELECT id FROM tareas WHERE (empleado_id=?)
2002-05-05 02:59:44,204 DEBUG 
[org.jboss.ejb.plugins.cmp.jdbc.JDBCFindByPrimaryKeyQuery.Actividad.findByPrimaryKey] 
Executing SQL: SELECT id FROM actividades WHERE id=?
2002-05-05 02:59:44,264 DEBUG 
[org.jboss.ejb.plugins.cmp.jdbc.JDBCLoadEntityCommand.Actividad] Executing SQL: SELECT 
nombre, descripcion, perfil_id FROM actividades WHERE (id=?)
2002-05-05 02:59:44,295 DEBUG 
[org.jboss.ejb.plugins.cmp.jdbc.JDBCLoadRelationCommand.Actividad] Executing SQL: 
SELECT id FROM tareas WHERE (actividad_id=?)
2002-05-05 02:59:44,325 INFO [charlie.ejb.TareaBean] Finishing ejbPostCreate ****
----------------------------------

As you can see, the INSERT INTO command is executed in ejbCreate, not in ejbPostCreate!
That's why my foreing key fields are left empty (I don't have a foreign key 
constraint, so they are just left as NULL).

Does anybody have problems with FKs not populated in CMR?

This one looks like a TERRIBLE bug!

Thanks in advace

Ricardo Arguello


_______________________________________________________________

Have big pipes? SourceForge.net is looking for download mirrors. We supply
the hardware. You get the recognition. Email Us: [EMAIL PROTECTED]
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user


_______________________________________________________________

Have big pipes? SourceForge.net is looking for download mirrors. We supply
the hardware. You get the recognition. Email Us: [EMAIL PROTECTED]
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to