[jboss-user] [EJB 3.0] - Persisting an Entity Bean with a null attribute throws Trans
idtechnology
do-not-reply at jboss.com
Mon Dec 11 13:02:55 EST 2006
Hi there,
I'm a JBOSS/EJB3 newbie.
I have installed JBOSS 4.0.5 GA, JDK 1.5.0_05, Eclipse 3.2+JBOSSIDE 1.6.0 plugin. MYSQL 5, mysql-connector-java-3.1.13 driver
I'm trying to persist some entity beans under transaction. One of these beans has a null (non-key) attribute. Either When I call persist or when I perform a readonly query on that object I get a
javax.persistence.TransactionRequiredException: EntityManager must be access within a transaction
@Entity
@Table(name = "person", catalog = "take2", uniqueConstraints = {})
public class Person implements java.io.Serializable {
// Fields
protected long idPerson;
protected String name;
protected String srname;
protected String gender;
protected Integer bthdateDD;
protected Integer bthdateMm;
protected Integer bthdateyyyy;
protected String sInsCOde;
protected Long job;
protected Long bthplace;
public static final String GENDER_M = "M";
public static final String GENDER_F = "F";
....
}
Here I have a managed bean to create an instance of Person that I pass to an transacted EJB to manage persistence under transaction.
private PersonBean createDefaultPerson()
{
PersonBean pb = new PersonBean();
pb.setSrName("Siciliano");
pb.setName("Andrea");
pb.setGender(Persona.SESSO_M);
pb.setBthDateDD(19);
pb.setBthDateMM(11);
//BthDateyyyy is not set so it is null in the managed bean
pb.setAge(33);
pb.setBthplace(9852L);
.....
return pb;
}
then the ejb persists the bean but I get the exception..
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public MyBean insDati(PersonBean abean)
{
...
...
entitymanager.persist(abean);
..
..
}
the exception does not triggers if the PersonaBean instance has all its attributes set to not null values.
The database does not have a not null constraints on the non key values.
+-----------------+------------------+------+-----+---------+
| Field | Type | Null | Key | Default | Extra|
+-----------------+------------------+------+-----+---------+
| idPerson | bigint(20) | NO | PRI | NULL | auto_increment |
| name | varchar(45) | YES | | NULL |
| srname | varchar(45) | YES | | NULL |
| gender | varchar(1) | YES | | NULL |
| bthdateDD | int(10) unsigned | YES | | NULL
| bthdateMM | int(10) unsigned | YES | | NULL
| bthdateyyyy | int(10) unsigned | YES | | NULL
| sInsid | varchar(16) | YES | | NULL |
| job | bigint(20) | YES | | NULL |
| bthplace | bigint(20) | YES | | NULL |
+-----------------+------------------+------+-----+---------+
What's goin' on?
thanks
:G
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3992856#3992856
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3992856
More information about the jboss-user
mailing list