I am getting SQLGrammarException with Hibernate 4.1.6.
javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: ORA-01722: invalid number.
Same code works fine with Hibernate 4.1.2.
Did some debugging and found that it happens while loading collection (OneToMany or ManyToMany) with one of the join columns as Enum.
So if I query directly an entity which have enum as one of the id column Hibernate performs proper parameter binding
{code:java} @Entity @Table(name="some_table") public class Sometable { @Id @Column(name = "id") @GenericGenerator(... ) @GeneratedValue(...) private String id; @Id @Column(name = "type") @Enumerated(EnumType.STRING) private SomeEnum type;
...more } {code}
Log showing proper binding is done:
2017-01-12 12:08:04,560 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (http-/0.0.0.0:8080-1) binding parameter [1] as [VARCHAR] - C11154179 2017-01-12 12:08:04,560 TRACE [org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler] (http-/0.0.0.0:8080-1) Handling invocation of statement method [setString] 2017-01-12 12:08:04,560 TRACE [org.hibernate.engine.jdbc.internal.proxy.PreparedStatementProxyHandler] (http-/0.0.0.0:8080-1) Binding via setString: [1, C11154179] 2017-01-12 12:08:04,560 TRACE [org.hibernate.type.EnumType] (http-/0.0.0.0:8080-1) Binding {0} to parameter: 2 2017-01-12 12:08:04,560 TRACE [org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler] (http-/0.0.0.0:8080-1) Handling invocation of statement method [setObject] ****************** Can see Enum value TYPE_ABCD ************* 2017-01-12 12:08:04,560 TRACE [org.hibernate.engine.jdbc.internal.proxy.PreparedStatementProxyHandler] (http-/0.0.0.0:8080-1) Binding via setObject: [2, TYPE_ABCD, 12]
----
But when Querying an entity which is eagerly loading collection that is joined with Enum column, exception is thrown.
{code:java} @Entity @Table(name="another_table") public class Anothertable { @Id @Column(name = "id") @GenericGenerator(... ) @GeneratedValue(...) private String id;
@Id @Column(name = "type") @Enumerated(EnumType.STRING) private SomeEnum type; @OneToMany @JoinColumns ( { @JoinColumn(name="id", referencedColumnName="id"), @JoinColumn(name="type", referencedColumnName="type") }) private Set<Sometable> data;
...more } {code}
Log showing wrong binding while loading collection:
2017-01-12 12:08:04,670 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (http-/0.0.0.0:8080-1) binding parameter [1] as [VARCHAR] - C11154179 2017-01-12 12:08:04,670 TRACE [org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler] (http-/0.0.0.0:8080-1) Handling invocation of statement method [setString] 2017-01-12 12:08:04,670 TRACE [org.hibernate.engine.jdbc.internal.proxy.PreparedStatementProxyHandler] (http-/0.0.0.0:8080-1) Binding via setString: [1, C11154179] 2017-01-12 12:08:04,670 TRACE [org.hibernate.type.EnumType] (http-/0.0.0.0:8080-1) Binding {0} to parameter: {1} 2017-01-12 12:08:04,670 TRACE [org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler] (http-/0.0.0.0:8080-1) Handling invocation of statement method [setObject] *****************Problem is below [2, 4, 4]*************** 2017-01-12 12:08:04,670 TRACE [org.hibernate.engine.jdbc.internal.proxy.PreparedStatementProxyHandler] (http-/0.0.0.0:8080-1) Binding via setObject: [2, 4, 4] *****************]*************** 2017-01-12 12:08:04,671 TRACE [org.hibernate.loader.Loader] (http-/0.0.0.0:8080-1) Bound [3] parameters total
----
{code:java} // Test method @Test public void testCollectionFailing() { TypedQuery<Anothertable> query = em.createQuery( "select a from Anothertable a " + "where a.id = :id and a.type = :t ", Anothertable.class).setMaxResults(1); query.setParameter("id", "C11154179"); query.setParameter("t", SomeEnum.TYPE_ABCD);
} {code}
|
|