[Hibernate-JIRA] Created: (HHH-4024) <join>: <key>: different composite key
by Sandeep Vaid (JIRA)
<join>: <key>: different composite key
--------------------------------------
Key: HHH-4024
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4024
Project: Hibernate Core
Issue Type: Improvement
Components: core
Affects Versions: 3.3.2, 3.3.1, 3.3.0.SP1, 3.3.0.GA, 3.3.0.CR2, 3.3.0.CR1, 3.2.7, 3.2.6
Reporter: Sandeep Vaid
Priority: Critical
Presently hibernate doesn't support this..
I have Bond domain class which maps to 2 tables viz. BOND nad BONDBASIC. The composite-key of both these tables are different.
BOND -----> INVESTMENTID, USECODE, STARTTIME (as composite-key)
BONDBASIC ----> INVESTMENTID, INVESTMENTID2, STARTTIME, TYPE (as composite-key)
NOTE: This is a legacy database, which i cannot change..
In bond.hbm.xml:
<class name="BondBO" table="TBINVESTMENTPERIOD" optimistic-lock="version" >
<composite-id name="compBondBO" class="CompBondBO">
<key-property name="investmentId" column="INVESTMENTID"/>
<key-property name="useCode" column="USECODE"/>
<key-property name="startTime" column="STARTTIME"/>
</composite-id>
<version unsaved-value="undefined" name="version" column="VERSION" type="com.tietoenator.lis.common.db.Db2Timestamp" />
<join table="BONDBASIC">
<key>
<!-- <column name="INVESTMENTID"></column>-->
<!-- <column name="STARTTIMESTAMP"></column>-->
</key>
</join>
</class>
How to specify the FK and PK of BONDBASIC ?
Hibernate doesn't provide any way to specify this kind of 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, 6 months
[Hibernate-JIRA] Created: (HHH-4023) Fix for an issue where alias references are incorrectly replaced by the table name in an INSERT
by John Trimble (JIRA)
Fix for an issue where alias references are incorrectly replaced by the table name in an INSERT
-----------------------------------------------------------------------------------------------
Key: HHH-4023
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4023
Project: Hibernate Core
Issue Type: Patch
Components: query-hql
Affects Versions: 3.3.2, 3.2.7
Environment: Hibernate versions 3.2.7 and 3.3.2 on MySQL and HSQLDB.
Reporter: John Trimble
Attachments: branch_3_2_r17009_insert_subquery_alias_fix.patch, branch_3_3_r17009_insert_subquery_alias_fix.patch
In an INSERT, aliases defined in the top most FROM clause incorrectly have their references in subqueries replaced by the table name. For example, a query such as:
HQL: insert into Foo (id, someInt) select bar.id as id, bar.someInt as someInt from Bar bar where exists ( select innerbar from Bar innerbar where innerbar.id=bar.id )
becomes,
HSQLDB SQL: insert into Foo ( id, someInt ) select aliastable0_.id as col_0_0_, aliastable0_.someInt as col_1_0_ from Bar aliastable0_ where exists (select id from Bar aliastable1_ where aliastable1_.id=Bar.id)
Note the use of 'Bar.id' instead of 'aliastable0_.id' resulting in the following exception:
org.hibernate.exception.SQLGrammarException: could not execute update query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.hql.ast.exec.BasicExecutor.execute(BasicExecutor.java:87)
at org.hibernate.hql.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:398)
at org.hibernate.engine.query.HQLQueryPlan.performExecuteUpdate(HQLQueryPlan.java:259)
at org.hibernate.impl.SessionImpl.executeUpdate(SessionImpl.java:1142)
at org.hibernate.impl.QueryImpl.executeUpdate(QueryImpl.java:94)
...
Caused by: java.sql.SQLException: Column not found: BAR.ID in statement [insert into Foo ( id, someInt ) select aliastable0_.id as col_0_0_, aliastable0_.someInt as col_1_0_ from Bar aliastable0_ where exists (select id from Bar aliastable1_ where aliastable1_.id=Bar.id)]
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:528)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:95)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:88)
at org.hibernate.hql.ast.exec.BasicExecutor.execute(BasicExecutor.java:65)
... 27 more
This substitution is not always inappropriate, for example DELETE requires the replacement:
HQL: delete from Bar bar where exists ( select innerbar from Bar innerbar where bar.id=innerbar.id )
HSQLDB SQL: delete from Bar where exists ( select id from Bar insertinto1_ where Bar.id=insertinto1_.id)
However, I cannot think of a case where this behavior would be necessary for an INSERT, but perhaps there is one I haven't considered. Judging from the logs, it looks as though this may have worked at one point but broke due to a fix for http://opensource.atlassian.com/projects/hibernate/browse/HHH-1419.
I have attached a patch for this issue, which includes an added test for it. The fix causes aliases in an INSERT to be handled in the same manner as for a SELECT. Tested on HSQLDB and MySQL with all tests passing. The issue exists in both the http://anonsvn.jboss.org/repos/hibernate/core/branches/Branch_3_2/ and http://anonsvn.jboss.org/repos/hibernate/core/branches/Branch_3_3/ branches (both of which I've included patches for), and may exist in the http://anonsvn.jboss.org/repos/hibernate/core/trunk/ as well, but I couldn't get it to build for me.
Let me know if there are any issues with the patch--especially with regard to unintended side effects--and I'll gladly look into resolving them.
--
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, 6 months
[Hibernate-JIRA] Created: (HHH-4020) Unable to load PersistentMap with the schema attribute define in the annotation @Table
by Xavier Jodoin (JIRA)
Unable to load PersistentMap with the schema attribute define in the annotation @Table
--------------------------------------------------------------------------------------
Key: HHH-4020
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4020
Project: Hibernate Core
Issue Type: Bug
Affects Versions: 3.3.1
Reporter: Xavier Jodoin
Attachments: entities.zip
Hibernate: select permission0_.SecureItem_id as SecureItem1_4_, permission0_.permissions_id as permissi2_4_, (select a11.owner_id from Permission a11 where a11.id=permission0_.permissions_id) as formula0_4_, permission1_.id as id88_0_, permission1_.factoryDefault as factoryD2_88_0_, permission1_.owner_id as owner7_88_0_, permission1_.propertyCreate as property3_88_0_, permission1_.propertyDelete as property4_88_0_, permission1_.propertyEdit as property5_88_0_, permission1_.propertyReadOnly as property6_88_0_, permission1_.secureItem_id as secureItem8_88_0_, secureacce2_.id as id29_1_, secureacce2_.factoryDefault as factoryD2_29_1_, secureacce2_.code as code29_1_, secureacce2_.upperCode as upperCode29_1_, secureacce2_.version as version29_1_, secureacce2_1_.password as password30_1_, secureacce2_2_.activate as activate31_1_, secureacce2_2_.admin as admin31_1_, secureacce2_2_.configurator as configur3_31_1_, secureacce2_2_.email as email31_1_, secureacce2_2_.firstName as firstName31_1_, secureacce2_2_.language_id as language10_31_1_, secureacce2_2_.lastName as lastName31_1_, secureacce2_2_.middleName as middleName31_1_, secureacce2_2_.readOnly as readOnly31_1_, secureacce2_2_.salesRep_id as salesRep11_31_1_, case when secureacce2_2_.id is not null then 2 when secureacce2_1_.id is not null then 1 when secureacce2_3_.id is not null then 3 when secureacce2_.id is not null then 0 else -1 end as clazz_1_, secureitem3_.id as id87_2_, secureitem3_.factoryDefault as factoryD2_87_2_, secureitem3_.name as name87_2_, secureitem3_.parent_id as parent6_87_2_, secureitem3_.securityKey as security4_87_2_, secureitem3_.securityOverride as security5_87_2_, secureitem4_.id as id87_3_, secureitem4_.factoryDefault as factoryD2_87_3_, secureitem4_.name as name87_3_, secureitem4_.parent_id as parent6_87_3_, secureitem4_.securityKey as security4_87_3_, secureitem4_.securityOverride as security5_87_3_ from naid_security.SecureItem_Permission permission0_ left outer join naid_security.Permission permission1_ on permission0_.permissions_id=permission1_.id left outer join naid_security.SecureAccess secureacce2_ on permission1_.owner_id=secureacce2_.id left outer join naid_security.SecurityUser secureacce2_1_ on secureacce2_.id=secureacce2_1_.id left outer join Users secureacce2_2_ on secureacce2_.id=secureacce2_2_.id left outer join naid_security.SecurityGroup secureacce2_3_ on secureacce2_.id=secureacce2_3_.id left outer join naid_security.SecureItem secureitem3_ on permission1_.secureItem_id=secureitem3_.id left outer join naid_security.SecureItem secureitem4_ on secureitem3_.parent_id=secureitem4_.id where permission0_.SecureItem_id=?
33033 [Thread-7] ERROR com.netappsid.services.beans.LoaderBean - Class Loaded : SecureItem
Id : 32768
could not initialize a collection: [com.netappsid.security.bo.SecureItem.permissions#32770]
org.hibernate.exception.SQLGrammarException: could not initialize a collection: [com.netappsid.security.bo.SecureItem.permissions#32770]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:90)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.loader.Loader.loadCollection(Loader.java:2022)
at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:59)
at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:587)
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:83)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1743)
at org.hibernate.collection.AbstractPersistentCollection.forceInitialization(AbstractPersistentCollection.java:476)
at org.hibernate.Hibernate.initialize(Hibernate.java:332)
at com.netappsid.dao.GenericDAO.initializeProxy(GenericDAO.java:1200)
at com.netappsid.security.bo.dao.SecureItemDAO.loadSecureItemAssociation(SecureItemDAO.java:29)
at com.netappsid.security.bo.dao.SecureItemDAO.loadSecureItemAssociation(SecureItemDAO.java:26)
at com.netappsid.security.bo.dao.SecureItemDAO.loadAssociations(SecureItemDAO.java:16)
at com.netappsid.services.beans.LoaderBean.findById(LoaderBean.java:140)
at com.netappsid.services.beans.LoaderBean_$$_javassist_43._d27findById(LoaderBean_$$_javassist_43.java)
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 com.netappsid.ejb3.naming.AbstractService$2.invoke(AbstractService.java:140)
at com.netappsid.services.beans.LoaderBean_$$_javassist_43.findById(LoaderBean_$$_javassist_43.java)
at com.netappsid.security.gui.SecurityAdminGUI$1$1.run(SecurityAdminGUI.java:101)
Caused by: java.sql.SQLSyntaxErrorException: Table/View 'PERMISSION' does not exist.
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement.<init>(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement20.<init>(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement30.<init>(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement40.<init>(Unknown Source)
at org.apache.derby.jdbc.Driver40.newEmbedPreparedStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement(Unknown Source)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:534)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:452)
at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:161)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1573)
at org.hibernate.loader.Loader.doQuery(Loader.java:696)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
at org.hibernate.loader.Loader.loadCollection(Loader.java:2015)
... 19 more
Caused by: java.sql.SQLException: Table/View 'PERMISSION' does not exist.
at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown Source)
... 39 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
15 years, 6 months