Help needed for JPA / hibernate - problems with creating entity classes

I started creating JPA / hibernate mappings for legacy Oracle-based databases. At one (early ...) point, I have a many-to-many relationship between tables (FOO, BAR, join table with extra fields: FOO_BAR). Thus, I defined three objects, created a built-in Id class for the connection table, strictly following some examples from a good (?!) Book.

I can select Foo, but whenever I try to read the bars associated with it from the result set, I get wither "SQLException: no data" or "SQLException: general error (S1000)". I can switch between them just by changing some java types of beans object ...

The log contains the following line n of the "No data" error case:

INFO org.hibernate.type.LongType - could not read column value from result set: Foo1_2_; No data found

Columns FOO_ID and BAR_ID are defined as NUMBER(22). At first I tried types Long, resulting in "No data", Doubleresulting in a "General Error". Then I read somewhere that the standard display for NUMBERis BigDecimal(-> "General error"), I tried instead BigInteger(-> "No data").

I'm lost.

When I take the sql statement from the logs and use it with the native jdbc ... it works fine.

PreparedStatement prep = con.prepareStatement(sqlQueryFromHibernateLogs);
prep.setBigDecimal(1, new  BigDecimal(1));
ResultSet rs = prep.executeeQuery();  // result set has the correct values...

Any help, suggestions, pointers to useful resources are much appreciated. Oh, one final note: I am "forced" to use the JdbcOdbc bridge. This is a really outdated system ...


My select statement is as follows:

List<Foo> foos = em.createQuery("select f from Foo f order by f.name").getResultList();

Edit

. , (1.0.3.2). hibernate3.jar ( , Version#getVersionString() [WORKING]), hibernatexxx - 3.1.0.GA(validator) 3.4.0.GA(entitymanager).


2

. , :

Foo.java

@Entitiy @Table(name="FOO")
public class Foo {
  @Id @Column(name="FOO_ID")
  private BigInteger fooId;

  Foo(){}

  @OneToMany(mappedBy="foo")
  private Set<FooBar> fooBars = new HashSet<FooBar>();
}

Bar.java

@Entitiy @Table(name="BAR")
public class Bar {
  @Id @Column(name="BAR_ID")
  private BigInteger fooId;

  Bar(){}

  @OneToMany(mappedBy="bar")
  private Set<FooBar> fooBars = new HashSet<FooBar>();
}

FooBar.java

@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(){}
}

FOO_ID BAR_ID NUMBER(22) Oracle. " ", BigInteger Long, " " . SQL ...

+3
1

, , , ( , JdbcOdbc):

googeling, , () , - : a No data found SQLException . - , , JdbcOdbc, . , , , , hibernate/JPA.

: , ... , oracle oci. ()

, !

0

Source: https://habr.com/ru/post/1766235/


All Articles