[Hibernate-JIRA] Created: (HHH-2498) Lazy Inverse Map Bug?
by CannonBall (JIRA)
Lazy Inverse Map Bug?
---------------------
Key: HHH-2498
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2498
Project: Hibernate3
Type: Bug
Versions: 3.2.1, 3.2.2
Environment: Hibernate 3.2.2, Java5, MySQL 5 (InnoDB)
Reporter: CannonBall
Priority: Minor
Mapping documents:
<hibernate-mapping>
<class name="scratchpad.hibernate.A">
<id name="id">
<generator class="assigned"/>
</id>
<map name="bs" cascade="all-delete-orphan" inverse="true">
<key column="aId"/>
<map-key type="long" column="cId"/>
<one-to-many class="scratchpad.hibernate.B"/>
</map>
</class>
<class name="scratchpad.hibernate.B">
<id name="id">
<generator class="assigned"/>
</id>
<many-to-one name="a" class="scratchpad.hibernate.A" column="aId"/>
<many-to-one name="c" class="scratchpad.hibernate.C" column="cId" not-null="true"/>
</class>
<class name="scratchpad.hibernate.C">
<id name="id">
<generator class="assigned"/>
</id>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
long aId = 1l;
long bId = 2l;
long cId = 3l;
SessionFactory factory = new Configuration().configure()
.buildSessionFactory();
try {
Session s = factory.openSession();
try {
Transaction tx = s.beginTransaction();
try {
C c = new C(cId);
s.save(c);
A a = new A(aId);
B b = new B(bId);
b.setC(c);
b.setA(a);
a.getBs().put(cId, b);
s.save(a);
tx.commit();
} catch (Exception e) {
try {
tx.rollback();
} catch (Exception e2) {
// do nothing
}
throw e;
}
} finally {
s.close();
}
s = factory.openSession();
try {
Transaction tx = s.beginTransaction();
try {
A a = (A) s.load(A.class, aId);
a.getBs().remove(cId);
tx.commit();
} catch (Exception e) {
try {
tx.rollback();
} catch (Exception e2) {
// do nothing
}
throw e;
}
} finally {
s.close();
}
} finally {
factory.close();
}
Name and version of the database you are using: MySQL 5.0.33
The generated SQL (show_sql=true):
Hibernate: select b_.id, b_.aId as aId1_, b_.cId as cId1_ from B b_ where b_.id=?
Hibernate: insert into C (id) values (?)
Hibernate: insert into A (id) values (?)
Hibernate: insert into B (aId, cId, id) values (?, ?, ?)
Hibernate: select a0_.id as id0_0_ from A a0_ where a0_.id=?
Hibernate: select bs0_.aId as aId1_, bs0_.id as id1_, bs0_.cId as cId1_, bs0_.id as id1_0_, bs0_.aId as aId1_0_, bs0_.cId as cId1_0_ from B bs0_ where bs0_.aId=?
I've been having a confusing problem shown above, whereby A has a Map of Bs indexed using the id from an association with C. This Map is inversely mapped for A and with 'Cascade Delete Orphan'. In the second opened session above, where B is removed from A's Map and thus orphaned, B will not be deleted. I have observed B is only deleted if I either set 'lazy="false"' for A's Map or make an interaction with A's Map in the code (before B's removal) like 'a.getBs().get(cId)'. I suspect the lazy intializer is not initializing correctly in the above scenario.
The above scenario does not happen if A's Map is not inversely mapped but B's many-to-one with A is.
Can somebody shed some light on whether this is me using Hibernate incorrectly or is a bug?
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
15 years, 7 months
[Hibernate-JIRA] Created: (HHH-2881) PersistantBag.initializeFromCache can be intercepted by CollectionLoadContext.getLoadingCollection and so corrupt the collection
by Pavol Zibrita (JIRA)
PersistantBag.initializeFromCache can be intercepted by CollectionLoadContext.getLoadingCollection and so corrupt the collection
--------------------------------------------------------------------------------------------------------------------------------
Key: HHH-2881
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2881
Project: Hibernate3
Issue Type: Bug
Environment: Hibernate Entity Manager 3.3.1 GA, oracle,
Reporter: Pavol Zibrita
It can occur that while PersistenBag.initializeFromCache is called to populate the collection from cache, the collection is populated also from CollectionLoadContext.getLoadingCollection, and so, the collection is filled with more data than needed. As the initializeFromCache uses direct access to the property this.bag, it will continue loading the collection. Here is the stack trace of what happens:
PersistentBag.beforeInitialize(CollectionPersister, int) line: xx //here is the same collection reinitialized again, and loaded again
CollectionLoadContext.getLoadingCollection(CollectionPersister, Serializable) line: 127
EntityLoader(Loader).readCollectionElement(Object, Serializable, CollectionPersister, CollectionAliases, ResultSet, SessionImplementor) line: 1003
EntityLoader(Loader).readCollectionElements(Object[], ResultSet, SessionImplementor) line: 646
EntityLoader(Loader).getRowFromResultSet(ResultSet, SessionImplementor, QueryParameters, LockMode[], EntityKey, List, EntityKey[], boolean) line: 591
EntityLoader(Loader).doQuery(SessionImplementor, QueryParameters, boolean) line: 701
EntityLoader(Loader).doQueryAndInitializeNonLazyCollections(SessionImplementor, QueryParameters, boolean) line: 236
EntityLoader(Loader).loadEntity(SessionImplementor, Object, Type, Object, String, Serializable, EntityPersister) line: 1860
EntityLoader(AbstractEntityLoader).load(SessionImplementor, Object, Object, Serializable) line: 48
EntityLoader(AbstractEntityLoader).load(Serializable, Object, SessionImplementor) line: 42
SingleTableEntityPersister(AbstractEntityPersister).load(Serializable, Object, LockMode, SessionImplementor) line: 3044
DefaultLoadEventListener.loadFromDatasource(LoadEvent, EntityPersister, EntityKey, LoadEventListener$LoadType) line: 395
DefaultLoadEventListener.doLoad(LoadEvent, EntityPersister, EntityKey, LoadEventListener$LoadType) line: 375
DefaultLoadEventListener.load(LoadEvent, EntityPersister, EntityKey, LoadEventListener$LoadType) line: 139
DefaultLoadEventListener.proxyOrLoad(LoadEvent, EntityPersister, EntityKey, LoadEventListener$LoadType) line: 195
DefaultLoadEventListener.onLoad(LoadEvent, LoadEventListener$LoadType) line: 103
SessionImpl.fireLoad(LoadEvent, LoadEventListener$LoadType) line: 878
SessionImpl.internalLoad(String, Serializable, boolean, boolean) line: 846
ManyToOneType(EntityType).resolveIdentifier(Serializable, SessionImplementor) line: 557
ManyToOneType.assemble(Serializable, SessionImplementor, Object) line: 196
TypeFactory.assemble(Serializable[], Type[], SessionImplementor, Object) line: 420
CacheEntry.assemble(Serializable[], Object, Serializable, EntityPersister, Interceptor, EventSource) line: 96
CacheEntry.assemble(Object, Serializable, EntityPersister, Interceptor, EventSource) line: 82
DefaultLoadEventListener.assembleCacheEntry(CacheEntry, Serializable, EntityPersister, LoadEvent) line: 553
DefaultLoadEventListener.loadFromSecondLevelCache(LoadEvent, EntityPersister, LoadEventListener$LoadType) line: 508
DefaultLoadEventListener.doLoad(LoadEvent, EntityPersister, EntityKey, LoadEventListener$LoadType) line: 357
DefaultLoadEventListener.load(LoadEvent, EntityPersister, EntityKey, LoadEventListener$LoadType) line: 139
DefaultLoadEventListener.proxyOrLoad(LoadEvent, EntityPersister, EntityKey, LoadEventListener$LoadType) line: 195
DefaultLoadEventListener.onLoad(LoadEvent, LoadEventListener$LoadType) line: 103
SessionImpl.fireLoad(LoadEvent, LoadEventListener$LoadType) line: 878
SessionImpl.internalLoad(String, Serializable, boolean, boolean) line: 846
ManyToOneType(EntityType).resolveIdentifier(Serializable, SessionImplementor) line: 557
ManyToOneType.assemble(Serializable, SessionImplementor, Object) line: 196
PersistentBag.initializeFromCache(CollectionPersister, Serializable, Object) line: xxx //NOW HERE IS THE Bag initializing from cache, it fails, see top of the stack!!
CollectionCacheEntry.assemble(PersistentCollection, CollectionPersister, Object) line: 35
DefaultInitializeCollectionEventListener.initializeCollectionFromCache(Serializable, CollectionPersister, PersistentCollection, SessionImplementor) line: 130
DefaultInitializeCollectionEventListener.onInitializeCollection(InitializeCollectionEvent) line: 48
SessionImpl.initializeCollection(PersistentCollection, boolean) line: 1716
PersistentBag(AbstractPersistentCollection).forceInitialization() line: 454
StatefulPersistenceContext.initializeNonLazyCollections() line: 794
QueryLoader(Loader).doQueryAndInitializeNonLazyCollections(SessionImplementor, QueryParameters, boolean) line: 241
QueryLoader(Loader).doList(SessionImplementor, QueryParameters) line: 2220
QueryLoader(Loader).listIgnoreQueryCache(SessionImplementor, QueryParameters) line: 2104
QueryLoader(Loader).list(SessionImplementor, QueryParameters, Set, Type[]) line: 2099
QueryLoader.list(SessionImplementor, QueryParameters) line: 378
QueryTranslatorImpl.list(SessionImplementor, QueryParameters) line: 338
HQLQueryPlan.performList(QueryParameters, SessionImplementor) line: 172
SessionImpl.list(String, QueryParameters) line: 1121
QueryImpl.list() line: 79
QueryImpl.getResultList() line: 66
//some stack before, uninportant
Small fix to the PersistantBag has resolved this issue, however I cannot tell if it is correct by some hibernate principles:
public void initializeFromCache(CollectionPersister persister, Serializable disassembled, Object owner)
throws HibernateException {
Serializable[] array = (Serializable[]) disassembled;
int size = array.length;
List<Object> elements = new ArrayList<Object>(size);
for ( int i = 0; i < size; i++ ) {
Object element = persister.getElementType().assemble( array[i], getSession(), owner );
if ( element!=null ) {
elements.add( element );
}
}
beforeInitialize( persister, size );
for ( Object element : elements ) {
this.bag.add( element );
}
}
Difference is, before the this.bag.add(element) was called in first cycle, where the line of getting the element could cause reinitializing the collection and filling it up. There are various possibilities how to fix the problem, but I don't know if the fix is at the right place!
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
15 years, 7 months
[Hibernate-JIRA] Created: (HHH-2355) CGLIBLazyInitializer can not access a public member if parent class is not public
by Daniel Beland (JIRA)
CGLIBLazyInitializer can not access a public member if parent class is not public
---------------------------------------------------------------------------------
Key: HHH-2355
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2355
Project: Hibernate3
Type: Bug
Versions: 3.2.1
Reporter: Daniel Beland
In hibernate 3.2.1, CGLIBLazyInitializer cannot acces a public method if it has been inherited from a parent class that is not public.
Let's say we have a class A, modifier = default (package) with a public method getName() (and setName(String name)).
Then I create a public class B that extends A.
in my code I can retrieve B from the database:
B b = session.load(B.class, new Integer(1), LockMode.NONE);
I receive b with all the values set correctly (So at this point, Hibernate was able to use the method setName() correctly).
In my code if I then try to use b.getName(), I receive and error:
java.lang.IllegalAccessException-->Class org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer can not access a member of class A with modifiers "public"
But I am not trying to access A.getName(), but B.getName() (which is a public method in a public class).
This was working perfectly with Hibernate 2.1.7c and 3.1.3.
The full information about my problem can be found here: http://forum.hibernate.org/viewtopic.php?t=969453
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
15 years, 8 months
[Hibernate-JIRA] Created: (HHH-2745) NullPointerException when eager fetching joined many-to-many with native SQL query
by Mihail Fridliand (JIRA)
NullPointerException when eager fetching joined many-to-many with native SQL query
----------------------------------------------------------------------------------
Key: HHH-2745
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2745
Project: Hibernate3
Issue Type: Bug
Components: core
Affects Versions: 3.2.1
Environment: Hibernate 3.2.1, DB2
Reporter: Mihail Fridliand
NullPointerException when joining many-to-many assoziation with native SQL query:
java.lang.NullPointerException
at org.hibernate.loader.custom.sql.SQLQueryParser.resolveProperties(SQLQueryParser.java:182)
at org.hibernate.loader.custom.sql.SQLQueryParser.resolveCollectionProperties(SQLQueryParser.java:135)
at org.hibernate.loader.custom.sql.SQLQueryParser.substituteBrackets(SQLQueryParser.java:98)
at org.hibernate.loader.custom.sql.SQLQueryParser.process(SQLQueryParser.java:51)
at org.hibernate.loader.custom.sql.SQLCustomQuery.<init>(SQLCustomQuery.java:110)
at org.hibernate.engine.query.NativeSQLQueryPlan.<init>(NativeSQLQueryPlan.java:43)
at org.hibernate.engine.query.QueryPlanCache.getNativeSQLQueryPlan(QueryPlanCache.java:114)
at org.hibernate.impl.SessionFactoryImpl.checkNamedQueries(SessionFactoryImpl.java:444)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:351)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1291)
The SQLQueryReturnProcessor ignores many-to-many assoziations:
private void addCollection(String role, String alias, Map propertyResults) {
SQLLoadableCollection collectionPersister = ( SQLLoadableCollection ) factory.getCollectionPersister( role );
alias2CollectionPersister.put( alias, collectionPersister );
String suffix = generateCollectionSuffix();
log.trace( "mapping alias [" + alias + "] to collection-suffix [" + suffix + "]" );
alias2CollectionSuffix.put( alias, suffix );
collectionPropertyResultMaps.put( alias, propertyResults );
if ( collectionPersister.isOneToMany() ) {
SQLLoadable persister = ( SQLLoadable ) collectionPersister.getElementPersister();
addPersister( alias, filter( propertyResults ), persister );
}
}
Mapping of a many-to-many:
<hibernate-mapping>
<class name="A" table="A" schema="TEST" >
<set name="manyToMany" inverse="true" table="AC" >
<key>
<column name="A_OID" not-null="true" />
</key>
<many-to-many class="C">
<column name="C_OID" not-null="true" />
</many-to-many>
</set>
</class>
<class name="C" table="C" schema="TEST">
</class>
<resultset name="AandC">
<return alias="a" class="A"/>
<return-join alias="c" property="a.manyToMany"/>
</resultset>
<sql-query name="getAandC" resultset-ref="AandC" >
<![CDATA[
select DISTINCT {a.*},{c.*} from A a join AC ac on a.OID = ac.A_OID join C c on c.C_OID=ac.C_OID
]]>
</sql-query>
</hibernate-mapping>
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
15 years, 8 months
[Hibernate-JIRA] Created: (HHH-2276) Can not get N first results of query with DB2 dialect (neither with setMaxResults nor with setFetchSize)
by Fred (JIRA)
Can not get N first results of query with DB2 dialect (neither with setMaxResults nor with setFetchSize)
--------------------------------------------------------------------------------------------------------
Key: HHH-2276
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2276
Project: Hibernate3
Type: Bug
Components: query-criteria
Versions: 3.1.2
Environment: DB2 V7 version = DSN07012
DB OS = zOS
IBM DB2 JDBC Universal Driver Architecture
Version du pilote JDBC : 2.1.34
Using dialect: org.hibernate.dialect.DB2Dialect
Reporter: Fred
I can't get the N first records from a select request using the setMaxResults method.
HB generates a request that can not be understood by DB2 (select * from ( select rownumber() over() as rownumber etc.... see first stacktrace below)
Moreover, using setFetchSize does not work (see second stack trace below the first one).
Is there a way to tell HB to append " fetch first 10 rows only" to the query (as a workaround) ? Because my DB2 can understand that one :
select *
from MYTABLE
where numseq = '2'
fetch first 10 rows only
thanks !
Fred
STACK WITH SETMAXRESULTS :
Hibernate: select * from ( select rownumber() over() as rownumber_, * from A165D.TB3PARCV where TVOY='D' ) as temp_ where rownumber_ <= ?
[01/12/06 12:03:17:516 CET] 2d68c035 SystemOut O 12:03:17,516 67422 WARN JDBCExceptionReporter (logExceptions, 71 ) - SQL Error: -104, SQLState: 42601
12:03:17,516 67422 WARN JDBCExceptionReporter (logExceptions, 71 ) - SQL Error: -104, SQLState: 42601
12:03:17,516 67422 ERROR JDBCExceptionReporter (logExceptions, 72 ) - ILLEGAL SYMBOL "(". SOME SYMBOLS THAT MIGHT BE LEGAL ARE: , FROM INTO
12:03:17,516 67422 ERROR JDBCExceptionReporter (logExceptions, 72 ) - ILLEGAL SYMBOL "(". SOME SYMBOLS THAT MIGHT BE LEGAL ARE: , FROM INTO
12:03:17,516 67422 WARN JDBCExceptionReporter (logExceptions, 71 ) - SQL Error: -516, SQLState: 26501
12:03:17,516 67422 WARN JDBCExceptionReporter (logExceptions, 71 ) - SQL Error: -516, SQLState: 26501
12:03:17,547 67453 ERROR JDBCExceptionReporter (logExceptions, 72 ) - THE DESCRIBE STATEMENT DOES NOT SPECIFY A PREPARED STATEMENT
12:03:17,547 67453 ERROR JDBCExceptionReporter (logExceptions, 72 ) - THE DESCRIBE STATEMENT DOES NOT SPECIFY A PREPARED STATEMENT
12:03:17,547 67453 WARN JDBCExceptionReporter (logExceptions, 71 ) - SQL Error: -514, SQLState: 26501
12:03:17,547 67453 WARN JDBCExceptionReporter (logExceptions, 71 ) - SQL Error: -514, SQLState: 26501
12:03:17,578 67484 ERROR JDBCExceptionReporter (logExceptions, 72 ) - THE CURSOR SQL_CURLN300C4 IS NOT IN A PREPARED STATE
12:03:17,578 67484 ERROR JDBCExceptionReporter (logExceptions, 72 ) - THE CURSOR SQL_CURLN300C4 IS NOT IN A PREPARED STATE
12:03:17,578 67484 ERROR WAction (execute, 56 ) - org.hibernate.exception.SQLGrammarException: could not execute query
org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:65)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2153)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
at org.hibernate.loader.Loader.list(Loader.java:2024)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:117)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1607)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:121)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:169)
[...]
Caused by: com.ibm.db2.jcc.a.SqlException: ILLEGAL SYMBOL "(". SOME SYMBOLS THAT MIGHT BE LEGAL ARE: , FROM INTO
at com.ibm.db2.jcc.a.cy.e(cy.java:1507)
at com.ibm.db2.jcc.a.cy.a(cy.java:1117)
at com.ibm.db2.jcc.a.cy.a(cy.java:1103)
at com.ibm.db2.jcc.b.bd.h(bd.java:131)
at com.ibm.db2.jcc.b.bd.a(bd.java:42)
at com.ibm.db2.jcc.b.r.a(r.java:31)
at com.ibm.db2.jcc.b.bs.g(bs.java:149)
at com.ibm.db2.jcc.a.cy.l(cy.java:1097)
at com.ibm.db2.jcc.a.cz.bb(cz.java:1554)
at com.ibm.db2.jcc.a.cz.d(cz.java:1986)
at com.ibm.db2.jcc.a.cz.S(cz.java:424)
at com.ibm.db2.jcc.a.cz.executeQuery(cz.java:407)
at com.ibm.ws.rsadapter.jdbc.WSJdbcPreparedStatement.executeQuery(WSJdbcPreparedStatement.java:426)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:139)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1669)
at org.hibernate.loader.Loader.doQuery(Loader.java:662)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2150)
... 52 more
_____________________________________________________________________________________________________
STACK WITH SETFETCHSIZE() :
[01/12/06 12:20:57:250 CET] 28ea8033 SystemOut O 11:20:57,250 403719 ERROR WAction (execute, 56 ) - org.hibernate.MappingException: No Dialect mapping for JDBC type: 3
org.hibernate.MappingException: No Dialect mapping for JDBC type: 3
at org.hibernate.dialect.TypeNames.get(TypeNames.java:56)
at org.hibernate.dialect.TypeNames.get(TypeNames.java:81)
at org.hibernate.dialect.Dialect.getHibernateTypeName(Dialect.java:192)
at org.hibernate.loader.custom.CustomLoader.getHibernateType(CustomLoader.java:170)
at org.hibernate.loader.custom.CustomLoader.autoDiscoverTypes(CustomLoader.java:138)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1678)
at org.hibernate.loader.Loader.doQuery(Loader.java:662)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2150)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
at org.hibernate.loader.Loader.list(Loader.java:2024)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:117)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1607)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:121)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:169)
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
15 years, 8 months