3 Replies Latest reply on Jul 12, 2006 10:57 AM by andy

    Entity Bean behaves strangely with @OneToMany

    ISS IT Admin Newbie

      Hello everybody

      We've encountered a problem with an Entiy Bean. If we make an instance of the folowing bean persistent while the collection are empty they are added to the database correctly. The retrieval of the data works also.

      But: As soon as more than one collection contains more than one element we following problem occurs: The bean-data is fetched by a LEFT OUTER JOIN query (Found out with Ethereal). This causes the collections to contain as much elements as rows are returned by the DBMS.

      Collection1: 3 entries
      Collection2: 4 entries

      JOIN causes the collections to contain 12 entries (cartesian product)
      -> This is an undesired effect.

      Relevant bean code

      public class BibliographicData implements Serializable {
       private int id;
       private List<String> abstracts = new LinkedList<String>();
       private List<String> inventors = new LinkedList<String>();
       private List<String> applicants = new LinkedList<String>();
       public List<String> getAbstracts() {
       return abstracts;
       public List<String> getApplicants() {
       return applicants;
       public List<String> getInventors() {
       return inventors;

      Removal of @OneToMany causes JBoss to store the collections in serialized form. The problem disappears.

      Is there a clever way to store the collections in separate tables without separating them into individual entity beans?

      Thanks for your help!
      Regrads, Mike
      JBoss Configuration
      JBoss Version: 4.0.3 SP1
      Sun JRE5 Build 1.5.0_06-b05
      Debian Linux (Sarge)
      MySQL 5.0.22

      Changes in mysql-ds.xml
       <!-- sql to call when connection is created
       <new-connection-sql>some arbitrary sql</new-connection-sql>
       <!-- sql to call on an existing pooled connection when it is obtained from pool
       <check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>
       <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->