This week's book giveaway is in the Open Source Projects forum.
We're giving away four copies of Spark in Action and have Jean-Georges Perrin on-line!
See this thread for details.
Win a copy of Spark in Action this week in the Open Source Projects forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

@OneToMany Example In JPA with transaction type JTA

Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I need a sample code for @OneToMany relationship.

i have a entity as follows:

bean is getting deployed successfully in jboss5.1.0.GA without any problem and table is getting created.

I have EmployeeFacade Stateless Session Bean as follows:

PhoneNumberFacade Stateless Session Bean as follows:

both EmployeeFacade, PhoneNumberFacade inherits :


Client :

ERROR [AbstractFlushingEventListener] Could not synchronize database state with session


Caused by: java.sql.BatchUpdateException: ORA-01400: cannot insert NULL into ("EXAMPLE"."PHONENUMBER"."EMPLOYEE_ID")

at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(
at org.jboss.resource.adapter.jdbc.WrappedStatement.executeBatch(
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(
at org.hibernate.jdbc.AbstractBatcher.executeBatch(
... 39 more

Please help me to resolve this problem.

Bennet Xavier X.
Ranch Hand
Posts: 514
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

In my copybook where I am writing interesting notes it is written:
To be an entity class must follow these rules:
1. class must be annotated with @Entity
2. class must contain primary key annotated by @Id
3. class must contain public or protected no-argument constructor
4. class annotated by @Entity must be top-level, class without implementing or extending something
5. entity class must be not final, must not contain final variable or methods.
Also it is written:
Persistence provider maps entity to table thanks to annotation.
Do you have persistence provider configured in persistence.xml. If not then look at my persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns=""; xmlns:xsi=""; xsi:schemaLocation="">;
<persistence-unit name="OlympicsPU" transaction-type="JTA">
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/olympics?zeroDateTimeBehavior=convertToNull"/>
<property name="javax.persistence.jdbc.password" value="123456"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.user" value="root"/>
Posts: 1104
Netbeans IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bennet,
In your case Employee is the parent and PhoneNumber is the child. So, the usual way to do is to create the parent object and add the child objects via the list and then persist the parent object (rather than the child object).
In your case, you should persist the Employee object via the EmployeeFacade (and the PhoneNumber object(s) should be added to the List<PhoneNumber>).
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic