[Hibernate-JIRA] Created: (HHH-4832) Secondary tables do not work in JOINED or TABLE_PER_CLASS inheritance strategies
by Simon Godden (JIRA)
Secondary tables do not work in JOINED or TABLE_PER_CLASS inheritance strategies
--------------------------------------------------------------------------------
Key: HHH-4832
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4832
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.3.2
Environment: Hibernate 3.3.2, Postgres 8.4.2
Reporter: Simon Godden
Attachments: hibernatetest2.tgz
I have a class hierarchy as follows:
{noformat}
Abstract RootClass (Mapped Superclass)
|
\ /
Abstract IntermediateClass (Entity)
| |
\ / \ /
LeafClass (Entity) LeafClass2 (Entity)
{noformat}
The following table shows which attributes are on each class:
||Class||Attribute||Table||
|RootClass|field1|rootclass|
|IntermediateClass|field2|intermediateclass|
|LeafClass|field3|leafclass|
|LeafClass|field4|leafclass2|
|AnotherLeafClass|field5|anotherleafclass|
|AnotherLeafClass|field6|anotherleafclass2|
Using {{InheritanceType.SINGLE_TABLE}}, it works.
Using {{InheritanceType.JOINED}} or {{InheritanceType.TABLE_PER_CLASS}} at the {{IntermediateClass}} level causes different errors:
Using {{InheritanceType.JOINED}} causes an incorrect insert statement which thinks that {{field4}} is on table {{leafclass}} rather than {{leafclass2}}:
{noformat}
Hibernate:
insert
into
LeafClass
(field1, field2, field3, field4, id)
values
(?, ?, ?, ?, ?)
Exception in thread "main" [22/01/10 03:17:53:053 GMT] WARN util.JDBCExceptionReporter: SQL Error: 0, SQLState: null
[22/01/10 03:17:53:053 GMT] ERROR util.JDBCExceptionReporter: Batch entry 0 insert into LeafClass (field1, field2, field3, field4, id) values (foo1, foo2, foo3, foo4, 1) was aborted. Call getNextException to see the cause.
[22/01/10 03:17:53:053 GMT] WARN util.JDBCExceptionReporter: SQL Error: 0, SQLState: 42703
[22/01/10 03:17:53:053 GMT] ERROR util.JDBCExceptionReporter: ERROR: column "field4" of relation "leafclass" does not exist
{noformat}
Using {{InheritanceType.TABLE_PER_CLASS}} causes the following error as the session factory is built:
{noformat}
[22/01/10 03:06:05:005 GMT] INFO cfg.SettingsFactory: Echoing all SQL to stdout
[22/01/10 03:06:05:005 GMT] INFO cfg.SettingsFactory: Statistics: disabled
[22/01/10 03:06:05:005 GMT] INFO cfg.SettingsFactory: Deleted entity synthetic identifier rollback: disabled
[22/01/10 03:06:05:005 GMT] INFO cfg.SettingsFactory: Default entity-mode: pojo
[22/01/10 03:06:05:005 GMT] INFO cfg.SettingsFactory: Named query checking : enabled
[22/01/10 03:06:05:005 GMT] INFO impl.SessionFactoryImpl: building session factory
[22/01/10 03:06:06:006 GMT] ERROR hibernate.AssertionFailure: an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session)
org.hibernate.AssertionFailure: Table leafclass2 not found
at org.hibernate.persister.entity.JoinedSubclassEntityPersister.getTableId(JoinedSubclassEntityPersister.java:480)
at org.hibernate.persister.entity.JoinedSubclassEntityPersister.<init>(JoinedSubclassEntityPersister.java:259)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:87)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:267)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1341)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)
at tests.inheritdomain.SessionManager.initialiseSessionFactory(SessionManager.java:23)
at tests.inheritdomain.SessionManager.openSession(SessionManager.java:14)
at tests.inheritdomain.TestSecondaryTablesInInheritance.test(TestSecondaryTablesInInheritance.java:20)
at tests.inheritdomain.TestSecondaryTablesInInheritance.main(TestSecondaryTablesInInheritance.java:44){noformat}
A minimal test case is attached as an maven and eclipse project. mvn test will show the error. I have not created a test case for each inheritance type - you will have to change it in the intermediate domain class to see the other error.
--
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
13 years, 10 months
[Hibernate-JIRA] Created: (HHH-2470) Use of session.createSQLQuery causes memory leak
by Bjørn Bjerkeli (JIRA)
Use of session.createSQLQuery causes memory leak
-------------------------------------------------
Key: HHH-2470
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2470
Project: Hibernate3
Type: Bug
Components: query-sql
Versions: 3.1.3
Environment: Win XP, Oracle 10g, Java 1.4.2
Reporter: Bjørn Bjerkeli
Attachments: TestCase.zip
NativeSQLQuerySpecification fails to properly implement equals and hashcode caused by lacking implementation of hashCode and equals in all SQLQueryReturn implementations and SQLQueryScalarReturn which are members of NativeSQLQuerySpecification. I can see that NativeSQLQuerySpecification has been changed in 3.2, but the problem is still there.
NativeSQLQuerySpecification instances are used as keys for retrieving and caching NativeSQLQueryPlan instances.
This causes the caching-mechanism to be pretty useless when Queries created by session.createSQLQuery because new entries will be added all the time in the QueryPlanCache and the SoftLimitMRUCache member.
So far so good, the more serious problem that is caused by this is stems from the implementation of SoftLimitMRUCache which again uses LRUMap in commons-collection. The put - method of the cache is not treadsafe, and that causes the following fragment in LRUMap to allow the map to grow beyond its maximumSize. That is bacause the containsKey method will return an incorrect result when concurrently updating the map.
public Object put( Object key, Object value ) {
int mapSize = size();
Object retval = null;
if ( mapSize >= maximumSize ) {
// don't retire LRU if you are just
// updating an existing key
if (!containsKey(key)) {
// lets retire the least recently used item in the cache
removeLRU();
}
}
retval = super.put(key,value);
return retval;
}
I have included a test-case that demonstrates:
1) Wrong implementation of equals and hashCode in NativeSQLQuerySpecification
2) Concurrent use of LRUMap causes the map to grow beyound it's max limit
3) Concurrent execution of session.createSQLQuery causes memory leak due to 1) and 2)
I would be more than happy to contribute to get this fixed. Just let me know.
--
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
13 years, 10 months
[Hibernate-JIRA] Created: (HHH-3221) Cascading performance problems when session contains many entities
by Yves Galante (JIRA)
Cascading performance problems when session contains many entities
------------------------------------------------------------------
Key: HHH-3221
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3221
Project: Hibernate3
Issue Type: Improvement
Components: core
Affects Versions: 3.3.0.CR1, 3.2.6, 3.2.5
Reporter: Yves Galante
Attachments: patchCascading.patch, SaveTest.zip
When session contains many entities, performence of cascading become very slow.
For each collection element the whole persistence context is searched (by StatefulPersistenceContext#getIndexInOwner() and StatefulPersistenceContext#getOwnerId) and its even searched twice when the collection is an indexed collection.
This patch optimize cascading operation by caching relation parent-child on a map.
eventSource.getPersistenceContext().addChildParent(child, parent);
action.cascade(eventSource, child, entityName, anything, isCascadeDeleteEnabled);
eventSource.getPersistenceContext().removeChildParent(child);
The test case save and flush 10 * 551 objects.
Before patch save object with cascading is more slow when session size grows.
After patch time of save stay same at each loop.
Output of the test case before the patch :
Save took 449 ms
Save took 669 ms
Save took 1042 ms
Save took 1464 ms
Save took 2481 ms
Save took 2741 ms
Save took 3807 ms
Save took 4344 ms
Save took 4975 ms
Save took 5251 ms
Total took 30906 ms
Output after the patch
Save took 445 ms
Save took 144 ms
Save took 164 ms
Save took 108 ms
Save took 93 ms
Save took 93 ms
Save took 93 ms
Save took 94 ms
Save took 91 ms
Save took 89 ms
Total took 4905 ms
--
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
13 years, 10 months
[Hibernate-JIRA] Created: (HHH-5266) NullPointer in toString of PersistentBag
by Jan Stolze (JIRA)
NullPointer in toString of PersistentBag
----------------------------------------
Key: HHH-5266
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5266
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.3.2
Reporter: Jan Stolze
We have created an interceptor which keeps track of changes during a running transaction so in case of a rollback we can log which changes where issued before the rollback is performed. Now we sometimes see in case a rollback is issued the following stacktrace:
exception in interceptor afterTransactionCompletion()
java.lang.NullPointerException
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.initializeCollectionFromCache(DefaultInitializeCollectionEventListener.java:116)
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:71)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1744)
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:366)
at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:108)
at org.hibernate.collection.PersistentBag.toString(PersistentBag.java:506)
at java.lang.String.valueOf(String.java:2826)
at java.lang.StringBuilder.append(StringBuilder.java:115)
at gti.db.DbRollbackLogginInterceptor$LogEntry.toString(DbRollbackLogginInterceptor.java:246)
at java.lang.String.valueOf(String.java:2826)
at java.lang.StringBuilder.append(StringBuilder.java:115)
at gti.db.DbRollbackLogginInterceptor.logRollback(DbRollbackLogginInterceptor.java:109)
at gti.db.DbRollbackLogginInterceptor.afterTransactionCompletion(DbRollbackLogginInterceptor.java:70)
at org.hibernate.impl.SessionImpl.afterTransactionCompletion(SessionImpl.java:455)
at org.hibernate.jdbc.JDBCContext.afterTransactionCompletion(JDBCContext.java:252)
at org.hibernate.transaction.JDBCTransaction.rollback(JDBCTransaction.java:208)
at org.hibernate.ejb.TransactionImpl.rollback(TransactionImpl.java:85)
We do not have (at this moment) a clear overview of what has happend and what the exact conditions are for this NPE to occur, but think it is still important enough to report.
--
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
13 years, 10 months
[Hibernate-JIRA] Created: (HHH-5354) Joining fixed-length CHAR field with VARCHAR field
by Will Sumekar (JIRA)
Joining fixed-length CHAR field with VARCHAR field
--------------------------------------------------
Key: HHH-5354
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5354
Project: Hibernate Core
Issue Type: Bug
Components: query-criteria
Affects Versions: 3.5.3
Environment: Windows XP, JDK 1.6.0_07, Hibernate 3, Oracle 10g
Reporter: Will Sumekar
Attachments: OracleCHAR.java
I join 2 tables on join condition:
table1.col1=table2.col2
col1 is NOT table1's PK, col2 is table1's PK
col1's type is CHAR(20), col2's type is VARCHAR(40)
I use Hibernate's Criteria API and it doesn't recognise the join condition and gives me 0 row.
I've trimmed the padding spaces by extending UserType but it doesn't work. Seems that it only works for retrieving a CHAR field, not joining it to another field.
Code:
Criteria pq = session.createCriteria(Devices.class).createAlias("PrisProduct", "pp");
pq.add(Restrictions.eq(field, value.trim()));
Collection pc = pq.list();
The Devices.hbm.xml excerpt:
<property name="dieCode" type="com.st.wma.datalayer.hibernate.util.OracleCHAR">
<column name="DIE_CODE" length="20" not-null="true" unique="true" />
</property>
<many-to-one name="PrisProduct" class="com.st.wma.datalayer.hibernate.model.PrisProduct" column="DIE_CODE" not-null="true" insert="false" update="false">
</many-to-one>
The PrisProduct.hbm.xml excerpt:
<set name="devices" table="DEVICES">
<key column="CAM_PRODUCT"/>
<one-to-many class="com.st.wma.datalayer.hibernate.model.Devices"/>
</set>
OracleCHAR code is attached.
It's not in my capacity to change the DB schema so I can't change the CHAR to VARCHAR.
environment: Windows XP, JDK 1.6.0_07, Hibernate 3, Oracle 10g
Thanks!
--
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
13 years, 10 months
[Hibernate-JIRA] Created: (HHH-5353) Incorrect results for Ms SQL native queries with anonymous columns
by Patras Vlad (JIRA)
Incorrect results for Ms SQL native queries with anonymous columns
------------------------------------------------------------------
Key: HHH-5353
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5353
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.5.3
Environment: Hibernate 3.5.3
Ms SQL Server 2005
Reporter: Patras Vlad
Priority: Minor
MS Sql Server does not name columns if they are not explicitly named or selected from a concrete table column. I presume hibernate uses the column name as a key and this causes incorrect results.
Fo example add the following method to a test:
{noformat} public void testNoNameColumns() {
Session s = openSession();
Transaction t = s.beginTransaction();
List l = s.createSQLQuery( "select 'A', 'B'" ).list();
assertEquals( 1, l.size() );
assertEquals( "A", ((Object[])l.get(0))[0] );
assertEquals( "B", ((Object[])l.get(0))[1] );
t.rollback();
s.close();
}{noformat}
The third assert will fail if you run it against a Ms SQL Server database. It passes with default database (used in a clean svn checkout).
No matter what the values are selected, if columns have no name, all will have the value of the first column. This also happens when selecting from a table and using a formula in the select:
{noformat}select a+b, c+d from abcdTable{noformat}
I don't expect an actual fix since it happens in rare cases, only on Ms SQL Server and the workaround is very simple (just add a name using "AS" keyword). However when this happens it may be difficult to find the cause, maybe if you could throw an exception if the query returns more than one unnamed column.
Note: I'm not sure if these columns have an associated term, I called them "anonymous columns" and "unnamed columns", Ms SQL Server Management Studio titles them "(no column name)".
--
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
13 years, 10 months