title: Help needed for JPA/hibernate - problems with creating entity classes
body: <p>I started creating JPA/hibernate mappings for a legacy database based on Oracle. At one (early...) point I have a many-to-many relation between to tables (FOO, BAR, join table with extra fields: FOO_BAR). So I defined three entities, created an embeddable Id class for the join table, strictly following some examples from a good (?!) book.</p>
  
  <p>I can select a Foo but whenever I try to read the related Bars from the result set, I get wither an "SQLException: No data found" or a "SQLException: General error (S1000)". I can switch between the two by just changing some java types of the entity beans...</p>
  
  <p>The log contains the following line n case of the "No data found" error:</p>
  
  <pre><code>INFO org.hibernate.type.LongType - could not read column value from result set: Foo1_2_; No data found
  </code></pre>
  
  <p>The columns FOO_ID and BAR_ID are defined as <code>NUMBER(22)</code>. I tried <code>Long</code> types first, this resulted in "No data found", <code>Double</code> led to "General error". Then I read somewhere that the standard mapping for <code>NUMBER</code> is <code>BigDecimal</code> (-> "General Error"), I tried <code>BigInteger</code> instead (-> "No data found").</p>
  
  <p>I'm lost.</p>
  
  <p>When I take the sql statement from the logs and use it with "native" jdbc, ... it works fine.</p>
  
  <pre><code>PreparedStatement prep = con.prepareStatement(sqlQueryFromHibernateLogs);
  prep.setBigDecimal(1, new  BigDecimal(1));
  ResultSet rs = prep.executeeQuery();  // result set has the correct values...
  </code></pre>
  
  <p>Any help, suggestions, pointers to helpful resources are highly appreciated. Oh, one final thing to mention: I'm 'forced' to use the JdbcOdbc bridge. It's really a legacy system...</p>
  
  <hr>
  
  <p>My select statement goes like this:</p>
  
  <pre><code>List&lt;Foo&gt; foos = em.createQuery("select f from Foo f order by f.name").getResultList();
  </code></pre>
  
  <hr>
  
  <p><strong>Edit</strong></p>
  
  <p>Versions - I'm bound to the hibernate libraries that are shipped with the play framework (1.0.3.2). The hibernate3.jar has no useful version information (nothing in Manifest, <code>Version#getVersionString()</code> says <code>[WORKING]</code>), the other hibernatexxx jars report as 3.1.0.GA (validator) or 3.4.0.GA (entitymanager).</p>
  
  <hr>
  
  <p><strong>Edit 2</strong></p>
  
  <p>I've reduced the classes to the absolute minimum with the errors still present. This is what I did:</p>
  
  <p><em>Foo.java</em></p>
  
  <pre><code>@Entitiy @Table(name="FOO")
  public class Foo {
    @Id @Column(name="FOO_ID")
    private BigInteger fooId;
  
    Foo(){}
  
    @OneToMany(mappedBy="foo")
    private Set&lt;FooBar&gt; fooBars = new HashSet&lt;FooBar&gt;();
  }
  </code></pre>
  
  <p><em>Bar.java</em></p>
  
  <pre><code>@Entitiy @Table(name="BAR")
  public class Bar {
    @Id @Column(name="BAR_ID")
    private BigInteger fooId;
  
    Bar(){}
  
    @OneToMany(mappedBy="bar")
    private Set&lt;FooBar&gt; fooBars = new HashSet&lt;FooBar&gt;();
  }
  </code></pre>
  
  <p><em>FooBar.java</em></p>
  
  <pre><code>@Entitiy @Table(name="FOOBAR")
  public class FooBar {
  
    @Embeddable
    public static class Id implements Serializable {
      @Column(name="FOO_ID")
      private BigInteger fooId;
      @Column(name="BAR_ID")
      private BigInteger barId;
  
      Id() {}
  
      // implementations of hashcode and equals
  
    }
  
    @Embedded
    private Id id = new Id();
  
    @ManytoOne @JoinColumn(name = "FOO_ID", insertable=false, updatable=false)
    private Foo foo;
  
    @ManytoOne @JoinColumn(name = "BAR_ID", insertable=false, updatable=false)
    private Bar bar;
  
    FooBar(){}
  }
  </code></pre>
  
  <p><code>FOO_ID</code> and <code>BAR_ID</code> are defined as <code>NUMBER(22)</code> on the the Oracle database. The above example leads to the "No data found" error, replacing <code>BigInteger</code> with <code>Long</code> results in the "General Error". And sending the very same SQL expression over the bridge gives a correct result set...</p>