Hi,
I have a parent entity with child entities being loaded using SubSelect and eager fetching.
I execute a query to retrieve all parents and get the following query which is not supported by Sybase 15.5 (dialect org.hibernate.dialect.SybaseASE15Dialect):
Hibernate 4.0.0 FINAL produce :
select
[... values0_ fields ...]
from B values0_
where
(
values0_.first, values0_.second
)
in
(
select
a0_.first, a0_.second
from A a0_
)
Code:
@Entity
public class A implements Serializable {
@Id
private String first;
@Id
private String second;
@Column
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinColumns(value = { @JoinColumn(name = "first"),
@JoinColumn(name = "second") })
@Fetch(FetchMode.SUBSELECT)
private List<B> values;
}
@Entity
public class B implements Serializable {
@Id
private String first;
@Id
private String second;
@Id
private String third;
@Column
private String value;
}
@Transactional
public class MyDAO implements IDAO {
@PersistenceContext
EntityManager em;
@Override
public List<T> getAll() {
return this.entityManager.createQuery(
"from A").getResultList();
}
}
Test :
Code:
...
@Inject
private IDAO dao;
@Test
public void testGetAll(){
dao.getAll();
}
...
Quote:
Caused by: javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Incorrect syntax near the keyword 'in'.
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1356)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1284)
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:261)
at com.myproject.dao.testGetAll(MyDAOTest.java:261)
... 8 more
Caused by: org.hibernate.exception.GenericJDBCException: Incorrect syntax near the keyword 'in'.
at org.hibernate.exception.internal.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:148)
at org.hibernate.exception.internal.SQLStateConverter.convert(SQLStateConverter.java:136)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:129)
at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
at $Proxy116.executeQuery(Unknown Source)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1978)
at org.hibernate.loader.Loader.doQuery(Loader.java:829)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:289)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
at org.hibernate.loader.Loader.loadCollectionSubselect(Loader.java:2242)
at org.hibernate.loader.collection.SubselectOneToManyLoader.initialize(SubselectOneToManyLoader.java:77)
at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:622)
at org.hibernate.event.internal.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:82)
at org.hibernate.internal.SessionImpl.initializeCollection(SessionImpl.java:1606)
at org.hibernate.collection.internal.AbstractPersistentCollection.forceInitialization(AbstractPersistentCollection.java:489)
at org.hibernate.engine.internal.StatefulPersistenceContext.initializeNonLazyCollections(StatefulPersistenceContext.java:906)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:294)
at org.hibernate.loader.Loader.doList(Loader.java:2463)
at org.hibernate.loader.Loader.doList(Loader.java:2449)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2279)
at org.hibernate.loader.Loader.list(Loader.java:2274)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:331)
at org.hibernate.internal.SessionImpl.listCustomQuery(SessionImpl.java:1585)
at org.hibernate.internal.AbstractSessionImpl.list(AbstractSessionImpl.java:224)
at org.hibernate.internal.SQLQueryImpl.list(SQLQueryImpl.java:156)
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:252)
... 12 more
Caused by: com.sybase.jdbc4.jdbc.SybSQLException: Incorrect syntax near the keyword 'in'.
at com.sybase.jdbc4.tds.Tds.a(Unknown Source)
at com.sybase.jdbc4.tds.Tds.nextResult(Unknown Source)
at com.sybase.jdbc4.tds.Tds.getResultSetResult(Unknown Source)
at com.sybase.jdbc4.tds.TdsCursor.open(Unknown Source)
at com.sybase.jdbc4.jdbc.SybStatement.executeQuery(Unknown Source)
at com.sybase.jdbc4.jdbc.SybPreparedStatement.executeQuery(Unknown Source)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:76)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:122)
... 35 more
Thanks a lot !