[Hibernate-JIRA] Created: (HHH-6314) UnionSubclassEntityPersister inefficient with unioned results in subquery
by Jon Todd (JIRA)
UnionSubclassEntityPersister inefficient with unioned results in subquery
-------------------------------------------------------------------------
Key: HHH-6314
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-6314
Project: Hibernate Core
Issue Type: Improvement
Components: core
Affects Versions: 3.6.5
Environment: mysql, linux, hibernate 3.2.0
Reporter: Jon Todd
*Background*
For hibernate queries (both HQL and criteria) where the entity being selected from is a superclass to a number of other concrete entities configured with table per concrete class, it appears that rather than applying the WHERE criteria to each unioned table, hibernate instead selects all results from all concrete tables in a subquery and then applies the WHERE criteria on the unioned result. Any realistic data sizes this is needlessly very inefficient.
*Concrete Example*
Consider we have the following entities: _BaseUser_, _HumanUser_, _AgentUser_ where the latter two classes extend _BaseUser_ with table per concrete class configuration.
When running a simple HQL query like:
{code:sql}
FROM BaseUser WHERE id = "1234"
{code}
The generated SQL looks something like this:
{code:sql}
SELECT this_.id, this_.userName, this_.agentName
FROM (
SELECT id, userName, null as agentName FROM HumanUser
UNION
SELECT id, null as userName, agentName FROM AgentUser
) this_
WHERE
this_.id = "1234";
{code}
Would have expected the generated SQL to be:
{code:sql}
SELECT this_.id, this_.userName, this_.agentName
FROM (
SELECT id, userName, null as agentName FROM HumanUser WHERE id = "1234"
UNION
SELECT id, null as userName, agentName FROM AgentUser WHERE id = "1234"
) this_
{code}
In the former case, this ends up creating a temp table that contains the combination of all data from every concrete instance, in the latter case it would create a temp table with a single row.
This implementation which appears to live in _org.hibernate.persister.entity.UnionSubclassEntityPersister. generateSubquery()_ has rendered the use of table per concrete class inheritance unusable in our application. Is there any short term solution?
--
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
[Hibernate-JIRA] Commented: (HHH-1268) Unidirection OneToMany causes duplicate key entry violation when removing from list
by Douglas Ferguson (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1268?page=c... ]
Douglas Ferguson commented on HHH-1268:
---------------------------------------
The proposed patch does not work. It generates bad sql.
We have been experiencing this problem and have gotten pretty close to resolving it. We have found that in CollectionUpdateAction there is an if statement that checks to see if the persistent collection "needsRecreate" which should be true for OneToMany, but as we run through the debugger we found that even though we have a @OneToMany annotation, it has "ManyToOne" at runtime.
Which means that instead of CollectionUpdateAction running "created" it runs "delete, update, insert" which blows up because of FK constraints.
The only place that seems to be setting ManyToOne is in CollectionBinder but the code gets a bit squirley, does anybody know this section well and why it would be flipping the annotation around?
if ( isCollectionOfEntities ) {
element =
new ManyToOne( mappings, collValue.getCollectionTable() );
collValue.setElement( element );
element.setReferencedEntityName( collType.getName() );
> Unidirection OneToMany causes duplicate key entry violation when removing from list
> -----------------------------------------------------------------------------------
>
> Key: HHH-1268
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1268
> Project: Hibernate Core
> Issue Type: Bug
> Affects Versions: 3.1, 3.5.6, 3.6.0
> Environment: 3.1 final
> MySql 4.1.14 using MYISAM tables
> Reporter: Rex Madden
> Assignee: Gail Badner
> Fix For: 3.2.x, 3.3.x, 3.6.6, 4.0.0.next
>
> Attachments: possible_solution.patch, src.zip
>
>
> Simple OneToMany parent/child relationship using the default table structure (2 tables and a join table)
> Add 3 children to the parent. Flush. Remove the first child. Flush throws error:
> Exception in thread "main" org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
> at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:69)
> at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
> at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:202)
> at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:230)
> at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:143)
> at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:296)
> at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
> at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:980)
> at UnidirectionalOneToManyRemoveFromListBug.main(UnidirectionalOneToManyRemoveFromListBug.java:27)
> 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:585)
> at com.intellij.rt.execution.application.AppMain.main(AppMain.java:86)
> Caused by: java.sql.BatchUpdateException: Duplicate key or integrity constraint violation, message from server: "Duplicate entry '5' for key 2"
> at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1461)
> at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
> at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:195)
> ... 11 more
> The problem is that there is a unique key on the relationship table that gets violated. The session removes the last row in the relationship table, then attempts to rewrite the child_id's. It fails since there is a uniqueness constraint on that column.
--
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
[Hibernate-JIRA] Created: (HHH-6312) Formula with paramters not working with direct queries`
by Waleed Badr (JIRA)
Formula with paramters not working with direct queries`
-------------------------------------------------------
Key: HHH-6312
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-6312
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.6.5
Environment: Hibernate version 3.6.5, HSQL database, Spring 3.0
Reporter: Waleed Badr
Priority: Blocker
Attachments: FormulaTest.zip
I created a formula with parameter accessing its value through a filter parameter like this:
@Formula("(label_id is null or label_id=:CurrentLabel.id)")
The CurrentLabel is a filter, and has a parameter named id. I set the filter's parameter after opening the session so the formula can get the value of it.
When i created a test-case by quering the entity that has the formula directly it fires this exception:
org.hibernate.exception.GenericJDBCException: could not execute query
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:140)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:128)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.loader.Loader.doList(Loader.java:2536)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276)
at org.hibernate.loader.Loader.list(Loader.java:2271)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:452)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1268)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
at com.company.app.Tests.testDirectQueryOnEntityWithFormula(Tests.java:78)
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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.sql.SQLException: Parameter not set
at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCPreparedStatement.checkParametersSet(Unknown Source)
at org.hsqldb.jdbc.JDBCPreparedStatement.fetchResult(Unknown Source)
at org.hsqldb.jdbc.JDBCPreparedStatement.executeQuery(Unknown Source)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1953)
at org.hibernate.loader.Loader.doQuery(Loader.java:802)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
at org.hibernate.loader.Loader.doList(Loader.java:2533)
... 38 more
Caused by: org.hsqldb.HsqlException: Parameter not set
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.error.Error.error(Unknown Source)
... 47 more
But when i query on the entity indirectly using another entity linked with it, the formula worked as expected.
I created a simple test-case, and attached it with this bug.
Thanks in advance for your help.
Waleed Badr
J2EE Architect
--
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
[Hibernate-JIRA] Created: (HHH-6309) Change org.hibernate.impl.SessionImpl.instantiate(EntityPersister , Serializable) to call persister.setIdentifier(...) if interceptor returns a non-null value
by Chris Webb (JIRA)
Change org.hibernate.impl.SessionImpl.instantiate(EntityPersister , Serializable) to call persister.setIdentifier(...) if interceptor returns a non-null value
--------------------------------------------------------------------------------------------------------------------------------------------------------------
Key: HHH-6309
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-6309
Project: Hibernate Core
Issue Type: Improvement
Components: core
Affects Versions: 3.6.5
Reporter: Chris Webb
org.hibernate.Interceptor.instantiate(String entityName, EntityMode entityMode, Serializable id) does not have any way of leveraging the EntityPersister to set the identifier so this should be done in SessionImpl.instantiate if the interceptor returns a non-null value by calling persister.setIdentifier(result, id, this).
Here is the completed change:
{code:title=org.hibernate.impl.SessionImpl.java|borderStyle=solid}
public Object instantiate(EntityPersister persister, Serializable id) throws HibernateException {
errorIfClosed();
checkTransactionSynchStatus();
Object result = interceptor.instantiate( persister.getEntityName(), entityMode, id );
if ( result == null ) {
result = persister.instantiate( id, this );
}
else {
// Set the id for the object instantiated by the interceptor.
persister.setIdentifier(result, id, this);
}
return result;
}
{code}
--
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
[Hibernate-JIRA] Created: (HBX-1188) Hibernate tool is not generating Pojo classes or Fetching children of database
by aditya.barat (JIRA)
Hibernate tool is not generating Pojo classes or Fetching children of database
------------------------------------------------------------------------------
Key: HBX-1188
URL: http://opensource.atlassian.com/projects/hibernate/browse/HBX-1188
Project: Hibernate Tools
Issue Type: Bug
Components: reverse-engineer
Environment: Hibernate tool version : 3.4.0.v20110215-1252-H31-GA ;
Database platform: MYSQL;
Eclipse version: Eclipse Java EE IDE for Web Developers.
Version: Helios Release
Build id: 20100617-1415
MYSQL driver: mysql-connector-java-5.1.6
Reporter: aditya.barat
Priority: Blocker
I have followed all steps required to use Hibernate reverse engineering tool.
1. Create the hibernate-cfg.xml
2. Create the hibernate console configuration.
3. Create the hibernate-reveng.xml
Also I have enabled full verbose debugging in the hibernate-log4j.properties by setting every parameter to 'debug'
When i configure a new launcher for Hibernate code generation and execute it. Even though I am not getting any errors in console or 'Error Log' but my Domain classes and .hbm.xml are not getting generated. I have selected .hbm.xml and Domain classes in the 'Export' option in my Code generation configuration.
Also if i were to 'refresh' the Database schema then it shows 'Fetching children of database' for some time and then there is no activity. Using the same connection information i am able to view the database tables etc with Razor SQL as well as SQL yog.
Request experts inputs as i have tried many times and verified the configurtaion matches to what is documented.
The only output i see in console is like this:
2011-06-10 22:52:15,332 INFO Worker-5 org.hibernate.connection.DriverManagerConnectionProvider - Using Hibernate built-in connection pool (not for production use!)
2011-06-10 22:52:15,428 INFO Worker-5 org.hibernate.connection.DriverManagerConnectionProvider - Hibernate connection pool size: 20
2011-06-10 22:52:15,428 INFO Worker-5 org.hibernate.connection.DriverManagerConnectionProvider - autocommit mode: false
2011-06-10 22:52:15,428 INFO Worker-5 org.hibernate.connection.DriverManagerConnectionProvider - using driver: org.gjt.mm.mysql.Driver at URL: jdbc:mysql://114.143.95.100:2499/MyTestDB
2011-06-10 22:52:15,429 INFO Worker-5 org.hibernate.connection.DriverManagerConnectionProvider - connection properties: {user=MydbUser, password=MyPassword}
2011-06-10 22:52:15,838 TRACE Worker-5 org.hibernate.connection.DriverManagerConnectionProvider - total checked-out connections: 0
2011-06-10 22:52:15,838 DEBUG Worker-5 org.hibernate.connection.DriverManagerConnectionProvider - opening new JDBC connection
2011-06-10 22:52:19,723 DEBUG Worker-5 org.hibernate.connection.DriverManagerConnectionProvider - created connection to: jdbc:mysql://114.143.95.100:2499/ Isolation Level: 4
2011-06-10 22:52:20,032 TRACE Worker-5 org.hibernate.connection.DriverManagerConnectionProvider - returning connection to pool, pool size: 1
2011-06-10 22:52:20,032 INFO Worker-5 org.hibernate.connection.DriverManagerConnectionProvider - cleaning up connection pool: jdbc:mysql://114.143.95.100:2499/MyTestDB
2011-06-10 22:53:31,620 INFO main org.hibernate.connection.DriverManagerConnectionProvider - Using Hibernate built-in connection pool (not for production use!)
2011-06-10 22:53:31,625 INFO main org.hibernate.connection.DriverManagerConnectionProvider - Hibernate connection pool size: 20
2011-06-10 22:53:31,625 INFO main org.hibernate.connection.DriverManagerConnectionProvider - autocommit mode: false
2011-06-10 22:53:31,625 INFO main org.hibernate.connection.DriverManagerConnectionProvider - using driver: org.gjt.mm.mysql.Driver at URL: jdbc:mysql://114.143.95.100:2499/MyTestDB
2011-06-10 22:53:31,625 INFO main org.hibernate.connection.DriverManagerConnectionProvider - connection properties: {user=MydbUser, password=MyPassword}
2011-06-10 22:53:33,905 INFO Worker-8 org.hibernate.connection.DriverManagerConnectionProvider - Using Hibernate built-in connection pool (not for production use!)
2011-06-10 22:53:33,906 INFO Worker-8 org.hibernate.connection.DriverManagerConnectionProvider - Hibernate connection pool size: 20
2011-06-10 22:53:33,906 INFO Worker-8 org.hibernate.connection.DriverManagerConnectionProvider - autocommit mode: false
2011-06-10 22:53:33,906 INFO Worker-8 org.hibernate.connection.DriverManagerConnectionProvider - using driver: org.gjt.mm.mysql.Driver at URL: jdbc:mysql://114.143.95.100:2499/MyTestDB
2011-06-10 22:53:33,906 INFO Worker-8 org.hibernate.connection.DriverManagerConnectionProvider - connection properties: {user=MydbUser, password=MyPassword}
2011-06-10 22:53:33,908 TRACE Worker-8 org.hibernate.connection.DriverManagerConnectionProvider - total checked-out connections: 0
2011-06-10 22:53:33,908 DEBUG Worker-8 org.hibernate.connection.DriverManagerConnectionProvider - opening new JDBC connection
2011-06-10 22:53:37,647 DEBUG Worker-8 org.hibernate.connection.DriverManagerConnectionProvider - created connection to: jdbc:mysql://114.143.95.100:2499/MyTestDB, Isolation Level: 4
2011-06-10 22:53:37,954 TRACE Worker-8 org.hibernate.connection.DriverManagerConnectionProvider - returning connection to pool, pool size: 1
2011-06-10 22:53:37,955 INFO Worker-8 org.hibernate.connection.DriverManagerConnectionProvider - cleaning up connection pool: jdbc:mysql://114.143.95.100:2499/MyTestDB
--
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
[Hibernate-JIRA] Created: (OGM-31) ConcurrentModificationException on ArrayList representing the collection
by Emmanuel Bernard (JIRA)
ConcurrentModificationException on ArrayList representing the collection
-------------------------------------------------------------------------
Key: OGM-31
URL: http://opensource.atlassian.com/projects/hibernate/browse/OGM-31
Project: Hibernate OGM
Issue Type: Bug
Components: core
Reporter: Emmanuel Bernard
Several instances can access the collection and try and update things. Since the underlying implementation is a simple ArrayList, you can get ConcurrentModificationException if someone reads it while someone else update it.
{code}
Exception in thread "pool-5-thread-2" java.util.ConcurrentModificationException
at java.util.AbstractList$Itr.checkForComodification(AbstractList.java:372)
at java.util.AbstractList$Itr.next(AbstractList.java:343)
at org.hibernate.ogm.util.impl.PropertyMetadataProvider.findMatchingTuple(PropertyMetadataProvider.java:137)
at org.hibernate.ogm.persister.Dehydrator.doRemovePropertyMetadata(Dehydrator.java:219)
at org.hibernate.ogm.persister.Dehydrator.dehydrate(Dehydrator.java:140)
at org.hibernate.ogm.persister.OgmEntityPersister.dehydrate(OgmEntityPersister.java:784)
at org.hibernate.ogm.persister.OgmEntityPersister.update(OgmEntityPersister.java:747)
at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:113)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:273)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:265)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:185)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:383)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:133)
at pt.ist.fenixframework.example.bankbench.hib.HibTxSystem.doIt(HibTxSystem.java:85)
at pt.ist.fenixframework.example.bankbench.TxCommand.run(TxCommand.java:14)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:680)
{code}
Problem:
- the collection should be copied on read and that's not the case
- the proper approach is to wrap it as an AtomicMap to benefit from the "diff" change
- longer term, we need the merge on conflict policy in Infinispan.
--
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