[Hibernate-JIRA] Created: (HHH-3400) hql insert doesn't work when inserting into a table with composite-id
by Ning Zhang (JIRA)
hql insert doesn't work when inserting into a table with composite-id
---------------------------------------------------------------------
Key: HHH-3400
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3400
Project: Hibernate3
Issue Type: Bug
Components: query-hql
Affects Versions: 3.2.6
Environment: 3.2.6GA, any database
Reporter: Ning Zhang
I have a table serving as an association table, so the Id of the table is just the ids from the linked tables. The mapping file looks like:
<class name="UserPt" table="user_pt" >
<composite-id>
<key-property name="userId" type="java.lang.Long" column="user_id"/>
<key-property name="ptId" type="java.lang.Long" column="pt_id"/>
</composite-id>
</class>
And I need to run some HQL to insert the association into the table like:
INSERT INTO UserPt(userId, ptId) SELECT user.id, pt.id FROM...........
Because of the complicated logic we have in the FROM statement, we cannot do this just by using collection mapping. When I run this HQL, it gives an error saying:
"can only generate ids as part of bulk insert with either sequence or post-insert style generators".
It looks like the hibernate is think the id is not set. I have tried different approaches like creating an separate id class, setting "mapped" to true, etc. But none of it solve the problem. The only thing I can do is defining a fake id in the hibernate mapping, which may introduce some problem in the future.
I would appreciate if someone can fix this issue or having some better work around for it. Thanks a lot.
--
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
16 years, 5 months
[Hibernate-JIRA] Created: (HHH-3415) Bugs in some Criteria-Expressions!
by Max Hartmann (JIRA)
Bugs in some Criteria-Expressions!
----------------------------------
Key: HHH-3415
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3415
Project: Hibernate3
Issue Type: Bug
Affects Versions: 3.3.0.CR1, 3.2.6
Environment: javase 5, postgresql 8
Reporter: Max Hartmann
I think there is a bug in some Criteria-Criterions:
e.g. NotNullExpression:
When I make an AliasProjection with the same name as the propertyName of the NotNullExpression, hibernate throws an exception.
I think this exception occurs because referencing aliases in the WHERE-CLAUSE are not alowed in SQL (NotNullExpression.toSQLString() invokes CriteriaQuery.getColumnsUsingProjection() to use aliases for the where-clause).
Code:
List<?> result = s.createCriteria(Test.class, "t1")
.createCriteria("test1", "t2")
.add(Restrictions.isNotNull("id"))
.setProjection(Projections.distinct(Projections.property("t2.id").as("id")))
.list();
Generated SQL:
select distinct t2x1_.id as y0_ from test this_ inner join test t2x1_ on this_.id=t2x1_.test1_id where y0_ is not null
Exception:
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2208)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2102)
at org.hibernate.loader.Loader.list(Loader.java:2097)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:96)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1573)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
at org.hibernate.impl.CriteriaImpl$Subcriteria.list(CriteriaImpl.java:458)
at test.TestApplication.main(TestApplication.java:52)
Caused by: org.postgresql.util.PSQLException: ERROR: column "y0_" does not exist
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1592)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1327)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:192)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:451)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:350)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:254)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:184)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1785)
at org.hibernate.loader.Loader.doQuery(Loader.java:674)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2205)
... 7 more
--
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
16 years, 5 months
[Hibernate-JIRA] Created: (HHH-3152) StaleStateException using many-to-many together with one-to-many
by Donatas Ciuksys (JIRA)
StaleStateException using many-to-many together with one-to-many
----------------------------------------------------------------
Key: HHH-3152
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3152
Project: Hibernate3
Issue Type: Bug
Components: core
Affects Versions: 3.2.6
Environment: Hibernate EntityManager 3.3.1 GA, Hibernate Annotations 3.3.0 GA, Hibernate Core 3.2.6 GA.
DB2 9.5 (production), Derby 10.3.2.1 (reproducible test case)
Reporter: Donatas Ciuksys
Attachments: db_schema.gif, ManyToMany.zip
I have many-to-many association between tables A and B (via join table A_B, see attached db_schema.gif). Join table has additional data columns, so I represent it as entity AB and have two one-to-many associations (A <-> AB and B <-> AB, with cascade=Cascade.REMOVE). Also I have many-to-many association between A and B (joinColumns are marked with insertable=false, updatable=false, though the marking/unmarking doesn't change the behaviour).
Table A is modeled as abstract entity A that is inherited by two concrete entities ATrue and AFalse. Table A has column BOOL_PROP (boolean property) of type INTEGER. ATrue spans objects with BOOL_PROP being true (1), AFalse - being false (0), column BOOL_PROP is used as Discriminator column.
The problem: having in database several ATrue and AFalse entities, it is impossible to delete ATrue entity - StaleStateException is being thrown:
Code fragment (p.getAllTrueA() return list of ATrue entities):
em.getTransaction().begin();
em.remove(p.getAllTrueA().get(0));
em.getTransaction().commit();
Log and exception stack trace:
Hibernate: delete from A_B where A=?
2008-03-03 18:02:10,313 [main] DEBUG org.hibernate.type.IntegerType - binding '4' to parameter: 1
Hibernate: delete from ADMIN.A_B where ID=?
2008-03-03 18:02:10,403 [main] DEBUG org.hibernate.type.IntegerType - binding '4' to parameter: 1
2008-03-03 18:02:10,473 [main] ERROR org.hibernate.event.def.AbstractFlushingEventListener - Could not synchronize database state with session
org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
at org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:61)
...
at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:54)
at manytomany.Main.run(Main.java:30)
at manytomany.Main.main(Main.java:15)
Exception in thread "main" javax.persistence.RollbackException: Error while commiting the transaction
at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:71)
at manytomany.Main.run(Main.java:30)
at manytomany.Main.main(Main.java:15)
Caused by: javax.persistence.OptimisticLockException: org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
at org.hibernate.ejb.AbstractEntityManagerImpl.wrapStaleStateException(AbstractEntityManagerImpl.java:654)
at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:59)
... 2 more
Caused by: org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
at org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:61)
...
The problem is that after:
Hibernate: delete from A_B where A=?
following statement is being executed:
Hibernate: delete from ADMIN.A_B where ID=?
The first statement deletes child A_B rows belonging to parent A. The second tries to delete what is already deleted.
Why I think it is related to many-to-many association: if I comment many-to-many association fields and getters/setters, problem is gone.
Attached is Eclipse project (standard java application), Derby DDL scripts. Following steps are needed to reproduce the problem:
1. Adjust the classpath (specify correct path to Hibernate EntityManager and its dependencies, Derby 10.3 derbyclient.jar)
2. Adjust database URL in /src/META-INF/persistence.xml (I'm using absolute path to DB, that is located at the projects root)
3. Start Derby network server (or adjust database URL to use embedded driver)
4. Start the application - it tries to delete ATrue entity and fails.
You can recreated the database if you wish - projects root folder contains DB_DDL.sql scripts. The program checks, whether the DB is empty, and if so, first fills it up with test data, then exits. Restart it again - it will load some ATrue entities and will try to delete one.
--
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
16 years, 5 months
[Hibernate-JIRA] Commented: (HHH-1696) Add outer join support for aliases on DetachedCriteria
by Chris Bredesen (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1696?page=c... ]
Chris Bredesen commented on HHH-1696:
-------------------------------------
Also adding this to EAP 4.2, 4.3:
https://jira.jboss.org/jira/browse/JBPAPP-1083
> Add outer join support for aliases on DetachedCriteria
> ------------------------------------------------------
>
> Key: HHH-1696
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1696
> Project: Hibernate3
> Issue Type: Improvement
> Components: query-criteria
> Affects Versions: 3.1.3, 3.2.0 cr1
> Environment: Hibernate 3.1, SQLServer2000
> Reporter: Mark Brocato
> Assignee: Diego Plentz
> Fix For: 3.2.6
>
> Attachments: HHH-1696.patch
>
>
> Recently, support for aliasing via an outer join was added to the Criteria class. The method
> createAlias(String associationPath, String alias, int joinType)
> , however, is not defined for DetachedCriteria. Adding this functionality would be extremely helpful for applications that expose detached criteria as their query api, and also for subqueries.
--
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
16 years, 5 months
[Hibernate-JIRA] Created: (EJB-375) getSingleResult potentially generates out of memory by calling list()
by Pascal P. Pochet (JIRA)
getSingleResult potentially generates out of memory by calling list()
---------------------------------------------------------------------
Key: EJB-375
URL: http://opensource.atlassian.com/projects/hibernate/browse/EJB-375
Project: Hibernate Entity Manager
Issue Type: Bug
Components: EntityManager
Affects Versions: 3.3.2.GA
Environment: any
Reporter: Pascal P. Pochet
calling list() while the user expects a single result has potential major flow: it's easy to trigger an out of memory situation where nobody would expect it...
like getSingleResult("select CURRENT_TIME from AN_ENTITY_CONTAINING_ZILLIONS_OF_RECORDS") ;
(and it is also a performance problem when it doesn't trigger the out of heap space... and a design issue: why fetching something the caller is not asking for ? with all the consequences on the cache...)
easy to circumvent by changing
List result = query.list();
to
List result = query.setMaxResults(2).list();
(so we keep the functionality of alerting developer when query is wrongly returning multiple results when it should not...)
and
em.throwPersistenceException( new NonUniqueResultException( "result returns " + uniqueResult.size() + " elements") );
to
em.throwPersistenceException( new NonUniqueResultException( "result returns more than 1 element") );
--
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
16 years, 5 months
[Hibernate-JIRA] Created: (HHH-3364) Missing table name + alias in FROM clause of generated SQL
by Istvan Kovacs (JIRA)
Missing table name + alias in FROM clause of generated SQL
----------------------------------------------------------
Key: HHH-3364
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3364
Project: Hibernate3
Issue Type: Bug
Components: core
Affects Versions: 3.3.0.CR1, 3.2.6
Environment: hsqldb
Reporter: Istvan Kovacs
Same sources as HHH-3362 and HHH-3363
select emp.name
from
Employee emp, Product p
where
emp.shop.stock[p] > 5
and
p.name='Product_10'
SQL (missing the table SHOP, aliased as shop_2)
select
employee0_.name as col_0_0_
from
Employee employee0_,
PRODUCT product1_,
SHOP_PRODUCT_STOCK stock3_
where
employee0_.SHOP_ID=shop2_.SHOP_ID
and shop2_.SHOP_ID=stock3_.SHOP_ID
and stock3_.PRODUCT_ID = product1_.PRODUCT_ID
and stock3_.AMOUNT>5
and product1_.name='Product_10'
Stack trace is from 3.3.0.CR1, but problem is also present in 3.2.6
java.sql.SQLException: Column not found: SHOP2_.SHOP_ID in statement [select employee0_.name as col_0_0_ from Employee employee0_, PRODUCT product1_, SHOP_PRODUCT_STOCK stock3_ where employee0_.SHOP_ID=shop2_.SHOP_ID and shop2_.SHOP_ID=stock3_.SHOP_ID and stock3_.PRODUCT_ID = product1_.PRODUCT_ID and stock3_.AMOUNT>5 and product1_.name='Product_10']
at org.hsqldb.jdbc.Util.throwError(Unknown Source)
at org.hsqldb.jdbc.jdbcPreparedStatement.<init>(Unknown Source)
at org.hsqldb.jdbc.jdbcConnection.prepareStatement(Unknown Source)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:505)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:423)
at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:139)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1547)
at org.hibernate.loader.Loader.doQuery(Loader.java:673)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2220)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at org.hibernate.console.HQLQueryPage.getList(HQLQueryPage.java:50)
at org.hibernate.eclipse.console.views.QueryPageViewer$ContentProviderImpl.getElements(QueryPageViewer.java:114)
at org.eclipse.jface.viewers.StructuredViewer.getRawChildren(StructuredViewer.java:937)
at org.eclipse.jface.viewers.ColumnViewer.getRawChildren(ColumnViewer.java:693)
at org.eclipse.jface.viewers.AbstractTableViewer.getRawChildren(AbstractTableViewer.java:1071)
at org.eclipse.jface.viewers.StructuredViewer.getFilteredChildren(StructuredViewer.java:871)
at org.eclipse.jface.viewers.StructuredViewer.getSortedChildren(StructuredViewer.java:994)
at org.eclipse.jface.viewers.AbstractTableViewer.internalRefreshAll(AbstractTableViewer.java:685)
at org.eclipse.jface.viewers.AbstractTableViewer.internalRefresh(AbstractTableViewer.java:633)
at org.eclipse.jface.viewers.AbstractTableViewer.internalRefresh(AbstractTableViewer.java:620)
at org.eclipse.jface.viewers.AbstractTableViewer$2.run(AbstractTableViewer.java:576)
at org.eclipse.jface.viewers.StructuredViewer.preservingSelection(StructuredViewer.java:1368)
at org.eclipse.jface.viewers.StructuredViewer.preservingSelection(StructuredViewer.java:1330)
at org.eclipse.jface.viewers.AbstractTableViewer.inputChanged(AbstractTableViewer.java:574)
at org.eclipse.jface.viewers.ContentViewer.setInput(ContentViewer.java:251)
at org.eclipse.jface.viewers.StructuredViewer.setInput(StructuredViewer.java:1606)
at org.hibernate.eclipse.console.views.QueryPageViewer.createTable(QueryPageViewer.java:218)
at org.hibernate.eclipse.console.views.QueryPageViewer.createControl(QueryPageViewer.java:197)
at org.hibernate.eclipse.console.views.QueryPageViewer.<init>(QueryPageViewer.java:154)
at org.hibernate.eclipse.console.views.QueryPageTabView.rebuild(QueryPageTabView.java:114)
at org.hibernate.eclipse.console.views.QueryPageTabView$1.contentsChanged(QueryPageTabView.java:78)
at org.hibernate.eclipse.console.views.QueryPageTabView$1.intervalAdded(QueryPageTabView.java:88)
at javax.swing.AbstractListModel.fireIntervalAdded(Unknown Source)
at org.hibernate.console.QueryPageModel.add(QueryPageModel.java:67)
at org.hibernate.console.KnownConfigurations$1.queryPageCreated(KnownConfigurations.java:90)
at org.hibernate.console.ConsoleConfiguration.fireQueryPageCreated(ConsoleConfiguration.java:419)
at org.hibernate.console.ConsoleConfiguration.access$5(ConsoleConfiguration.java:415)
at org.hibernate.console.ConsoleConfiguration$4.execute(ConsoleConfiguration.java:391)
at org.hibernate.console.execution.DefaultExecutionContext.execute(DefaultExecutionContext.java:65)
at org.hibernate.console.ConsoleConfiguration.executeHQLQuery(ConsoleConfiguration.java:383)
at org.hibernate.eclipse.hqleditor.HQLEditor.executeQuery(HQLEditor.java:406)
at org.hibernate.eclipse.console.actions.ExecuteQueryAction.execute(ExecuteQueryAction.java:72)
at org.hibernate.eclipse.console.actions.ExecuteQueryAction.run(ExecuteQueryAction.java:52)
at org.eclipse.jface.action.Action.runWithEvent(Action.java:498)
at org.hibernate.eclipse.console.actions.ExecuteQueryAction.runWithEvent(ExecuteQueryAction.java:56)
at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:546)
at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:490)
at org.eclipse.jface.action.ActionContributionItem$6.handleEvent(ActionContributionItem.java:443)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:938)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3682)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3293)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2389)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2353)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2219)
at org.eclipse.ui.internal.Workbench$4.run(Workbench.java:466)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:289)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:461)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:106)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:169)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:106)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:76)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:363)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:176)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:508)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:447)
at org.eclipse.equinox.launcher.Main.run(Main.java:1173)
--
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
16 years, 5 months