[Hibernate-JIRA] Updated: (HBX-524) Reverse of one-to-one relationships
by Anthony Patricio (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HBX-524?page=co... ]
Anthony Patricio updated HBX-524:
---------------------------------
Attachment: jpa-generation-patch.patch
@PrimaryColumnJoin was missing
> Reverse of one-to-one relationships
> -----------------------------------
>
> Key: HBX-524
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HBX-524
> Project: Hibernate Tools
> Issue Type: Bug
> Components: reverse-engineer
> Affects Versions: 3.1beta2
> Environment: HIbernate 3.1, Oracle 9i
> Reporter: Andrea Cattani
> Assignee: Anthony Patricio
> Fix For: 3.2.4.CR1
>
> Attachments: HBX-524.patch, HBX-524v2.patch, jpa-generation-patch.patch, one-to-one-marcio.patch, patch.txt
>
>
> Hi,
> I've posted this issue to the forum and got this response from Max, Hibernate Team:
> "the reveng tools does not detect this as a one-to-one. it probably could, so add a request/patch to jira."
> The problem I've faced is the following:
> I have two tables, let's say
> - table A with column ID (PK) and other fields
> - table B with column ID (PK) and other fields
> table B has a foreign key constraint against table A, from column ID to column ID (one-to-one)
> When I reverese the tables with the HibernateTools I have such a resultant mapping for table B:
> <class name="B" table="B" schema="SCHEMA">
> <id name="id" type="string">
> <column name="ID" length="12" />
> <generator class="assigned" />
> </id>
> <[b]many-to-one name[/b]="a" class="A" update="false" insert="false" fetch="select">
> <column name="ID" length="12" not-null="true" unique="true" />
> </many-to-one>
> ....
> And this one for table A:
> <class name="A" table="A" schema="SCHEMA">
> <id name="id" type="string">
> <column name="ID" length="12" />
> <generator class="assigned"/>
> </id>
> <set name="b" inverse="true">
> <key>
> <column name="ID" length="12" not-null="true" unique="true" />
> </key>
> <[b]one-to-many[/b] class="B" />
> </set>
> </class>
> while I was expecting something like:
> [i]<one-to-one name="a" class="A" constrained="true"/>[/i]
> in table B, and the same (or nothing) in table A
> Thank you
> Andi
--
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, 1 month
[Hibernate-JIRA] Commented: (HHH-1015) Incorrect SQL generated when one-to-many foreign key is in a discriminated subclass table
by Krasimir Chobantonov (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1015?page=c... ]
Krasimir Chobantonov commented on HHH-1015:
-------------------------------------------
Finally I had some time to inverstigate this issue.
It seems that there are 2 problems:
1) The collectionTable is not correctly set on the collection - e.g. instead of using the secondary table it is using the base table ( this is because persistentClass.getTable() on SINGLE_TABLE inheritance will return the base class).
The issue can be exposed if the Hibernate schema validation is turned on and the join column is on the secondary table (using @SecondaryTable annotation) but not in the base table. The problem can be fixed in
HbmBinder.bindCollectionSecondPass(Element node, Collection collection,
java.util.Map persistentClasses, Mappings mappings, java.util.Map inheritedMetas)
throws MappingException;
method.
The line that needs to be changed is on line 2402 (follow the code snippet)
collection.setCollectionTable( persistentClass.getTable() )
The new code need to iterate over the "Element node" method parameter and get the key/column/@name (all columns) and then try to find in the persistentClass the property that is mapped to the same column(s) and property.getPersistentClass().equals(persistentClass).
Once the property is found then (assumming that the property is saved in "property" variable)
the line
collection.setCollectionTable( persistentClass.getTable() )
needs to be changed to
collection.setCollectionTable( property.getValue().getTable() )
With this change the schema validation will pass.
2) The second issue is with the query itself as pointed in the begining of the JIRA issue. The problem here is in the
OneToManyJoinWalker.initStatementString(final OuterJoinLoadable elementPersister,
final String alias,
final int batchSize,
final String subquery)
throws MappingException;
Two things needs to be fixed here (at least)
- whereString generatation (line 122) should be prepared that the getKeyColumNames() may return columns that are mapped in the SecondaryTable instead of the base table.
The alias method parameter is actually pointing always to the base table.
Note the "elementPersister.fromTableFragment(alias)" in the fromClause generation
- oneToManyPersister.selectFragment on line 124 also needs to be prepared to handle this case
The alias in those two cases need to be changed to use the alias of the subclass table (the secondary table) and not the base table.
I'm not sure if this issue can be observed in the order by clause because I did not have the time to test that case.
The bottom line is that whenever we refer to the keyColumnNames then we need to not assume that those columns are always in the base table in case of SINGLE_TABLE inheritance because of the @SecondaryTable - the actual alias needs to be resolved and then to pass the new alias to the methods that will use the keyColumnNames.
Note: the exact lines of the code are obtained from the Hibernate version 3.3.1.GA source jar file.
> Incorrect SQL generated when one-to-many foreign key is in a discriminated subclass table
> -----------------------------------------------------------------------------------------
>
> Key: HHH-1015
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1015
> Project: Hibernate Core
> Issue Type: Bug
> Components: core
> Affects Versions: 3.1 beta 2
> Environment: Hibernate versions 3.1 beta 3 and 3.0.5
> Reporter: Steven Grimm
> Priority: Minor
>
> I have the following mappings describing a hierarchy of events and a class that the events refer to:
> <hibernate-mapping package="com.xyz">
> <class name="Event" table="event" discriminator-value="-1">
> <id name="Id" type="long" column="event_id"/>
> <discriminator column="event_type_id" type="integer" />
> <subclass name="EventPayer" discriminator-value="-3">
> <join table="event_payer">
> <key column="event_id" />
> <many-to-one name="payer" column="payer_id" class="Payer" />
> </join>
> <subclass name="EventPayerCreated" discriminator-value="1" />
> </subclass>
> </class>
> <class name="Payer" table="payer">
> <id name="payerId" column="payer_id" type="java.lang.Long"/>
> <set name="eventPayers" inverse="true" cascade="save-update">
> <key column="payer_id"/>
> <one-to-many class="EventPayer"/>
> </set>
> </class>
> </hibernate-mapping>
> When I fetch the Payer.eventPayers collection, Hibernate generates this SQL:
> select eventpayer0_.payer_id as payer7_1_,
> eventpayer0_.event_id as event1_1_,
> eventpayer0_.event_id as event1_5_0_,
> eventpayer0_1_.payer_id as payer2_6_0_,
> eventpayer0_.event_type_id as event2_5_0_
> from event eventpayer0_
> inner join event_payer eventpayer0_1_
> on eventpayer0_.event_id=eventpayer0_1_.event_id
> where eventpayer0_.payer_id=?
> The problem is that there is no event.payer_id column; payer_id is in the child table, not the parent. It appears that specifying a discriminated subclass in <one-to-many> is the same as specifying the superclass, or that Hibernate is ignoring the subclass's <join> element. As far as I can tell, this leaves no way to resolve bidirectional associations where one end of the association is in a discriminated subclass, which seems like a perfectly reasonable thing to want to do.
> I also tried changing <key column="payer_id"/> to <key property-ref="payer"/> in the Payer class's <set> element, but got similar behavior in the form of a "property not found" error: Hibernate is either looking in the superclass's properties rather than the subclass's or is ignoring the list of properties in the <join> 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, 1 month
[Hibernate-JIRA] Created: (HBX-1085) Receiving FileNotFoundException when Openning Mapping File in a multiple-source-folder project
by Thai (JIRA)
Receiving FileNotFoundException when Openning Mapping File in a multiple-source-folder project
----------------------------------------------------------------------------------------------
Key: HBX-1085
URL: http://opensource.atlassian.com/projects/hibernate/browse/HBX-1085
Project: Hibernate Tools
Issue Type: Bug
Components: consoleconfiguration
Affects Versions: 3.2LATER
Environment: Windows XP SP3
JDK 1.6.0_01
Eclipse 3.4.0 (Ganymede)
HibernateTools plugin 3.2.4 nightly build (HibernateTools-3.2.4.200808270817-nightly)
Reporter: Thai
I received the following exception when Openning Mapping File from Hibernate perspective:
java.io.FileNotFoundException: F:\projects\bizservice\src\main\filtered-resources\org\openbiz\bizservice\domain\User.hbm.xml (The system cannot find the path specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at org.hibernate.eclipse.console.actions.OpenFileActionUtils.getDocument(OpenFileActionUtils.java:233)
at org.hibernate.eclipse.console.actions.OpenFileActionUtils.rootClassInResource(OpenFileActionUtils.java:98)
at org.hibernate.eclipse.console.actions.OpenFileActionUtils.elementInResource(OpenFileActionUtils.java:86)
at org.hibernate.eclipse.console.actions.OpenFileActionUtils.getResource(OpenFileActionUtils.java:282)
at org.hibernate.eclipse.console.actions.OpenMappingAction.run(OpenMappingAction.java:120)
at org.hibernate.eclipse.console.actions.OpenMappingAction.run(OpenMappingAction.java:96)
at org.hibernate.eclipse.console.actions.OpenMappingAction.run(OpenMappingAction.java:71)
at org.eclipse.ui.actions.BaseSelectionListenerAction.runWithEvent(BaseSelectionListenerAction.java:168)
at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:583)
at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:500)
at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:411)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3823)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3422)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2382)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2346)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2198)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:493)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:288)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:488)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:113)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:193)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:382)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
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.eclipse.equinox.launcher.Main.invokeFramework(Main.java:549)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:504)
at org.eclipse.equinox.launcher.Main.run(Main.java:1236)
at org.eclipse.equinox.launcher.Main.main(Main.java:1212)
I find out the root cause in the following class org.hibernate.eclipse.console.actions.OpenFileActionUtils (lines 273-282)
for (int i = 0; i < packageFragmentRoots.length && resource == null; i++) {
//search in source folders.
if (packageFragmentRoots[i].getClass() == PackageFragmentRoot.class) {
IPackageFragmentRoot packageFragmentRoot = packageFragmentRoots[i];
IPath path = packageFragmentRoot.getPath().append(file.getValue());
resource = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
}
}
if (resource != null &&
elementInResource(consoleConfiguration, resource, element)) return resource;
The code assumes that if resource variable is not null, then the corresponding file exists at that location. In fact, when the file doesn't exist, the method org.eclipse.core.internal.resources.Container.getFile(..) might still return a not-null value (see http://mobius.inria.fr/eclipse-doc/org/eclipse/core/resources/IContainer....). As a result, a not-null file path will be passed to OpenFileActionUtils.elementInResource(..), and a FileNotFoundException will be thrown.
* Note that my project contains more than one source folder. This issue may not happen on one-source-folder project.
--
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, 1 month
[Hibernate-JIRA] Commented: (HHH-969) InformixDialect uses wrong sql for substring function
by Gail Badner (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-969?page=co... ]
Gail Badner commented on HHH-969:
---------------------------------
Yes, please attach a runnable unit test (Java + mapping) that reproduces the issue.
> InformixDialect uses wrong sql for substring function
> -----------------------------------------------------
>
> Key: HHH-969
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-969
> Project: Hibernate Core
> Issue Type: Bug
> Affects Versions: 3.0.5
> Environment: Hibernate 3.0.5, Informix 9.4
> Reporter: Scott Russell
>
> InformixDialect inherits function definitions from its parent Dialect. However, the default sql syntax for substring, substring(str, start, len) is not supported in Informix. Rather, Informix uses the following syntax: substring(str FROM start FOR len)
> The following line needs to be added to the InformixDialect constructor in order for this function to work correctly:
> registerFunction( "substring", new SQLFunctionTemplate(Hibernate.STRING, "substring(?1 FROM ?2 FOR ?3)" ));
> -Scott
--
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, 1 month
[Hibernate-JIRA] Reopened: (HBX-524) Reverse of one-to-one relationships
by Max Rydahl Andersen (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HBX-524?page=co... ]
Max Rydahl Andersen reopened HBX-524:
-------------------------------------
reopened since JPA generation is not correct.
I've committed a cpl minor fixes (i.e. API to have Ant and Eclipse control one-to-one generation) but more important
jdbc2cfg.OneToOneTest now runs schemavalidator to see if it matches the reveng database.
> Reverse of one-to-one relationships
> -----------------------------------
>
> Key: HBX-524
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HBX-524
> Project: Hibernate Tools
> Issue Type: Bug
> Components: reverse-engineer
> Affects Versions: 3.1beta2
> Environment: HIbernate 3.1, Oracle 9i
> Reporter: Andrea Cattani
> Assignee: Anthony Patricio
> Fix For: 3.2.4.CR1
>
> Attachments: HBX-524.patch, HBX-524v2.patch, one-to-one-marcio.patch, patch.txt
>
>
> Hi,
> I've posted this issue to the forum and got this response from Max, Hibernate Team:
> "the reveng tools does not detect this as a one-to-one. it probably could, so add a request/patch to jira."
> The problem I've faced is the following:
> I have two tables, let's say
> - table A with column ID (PK) and other fields
> - table B with column ID (PK) and other fields
> table B has a foreign key constraint against table A, from column ID to column ID (one-to-one)
> When I reverese the tables with the HibernateTools I have such a resultant mapping for table B:
> <class name="B" table="B" schema="SCHEMA">
> <id name="id" type="string">
> <column name="ID" length="12" />
> <generator class="assigned" />
> </id>
> <[b]many-to-one name[/b]="a" class="A" update="false" insert="false" fetch="select">
> <column name="ID" length="12" not-null="true" unique="true" />
> </many-to-one>
> ....
> And this one for table A:
> <class name="A" table="A" schema="SCHEMA">
> <id name="id" type="string">
> <column name="ID" length="12" />
> <generator class="assigned"/>
> </id>
> <set name="b" inverse="true">
> <key>
> <column name="ID" length="12" not-null="true" unique="true" />
> </key>
> <[b]one-to-many[/b] class="B" />
> </set>
> </class>
> while I was expecting something like:
> [i]<one-to-one name="a" class="A" constrained="true"/>[/i]
> in table B, and the same (or nothing) in table A
> Thank you
> Andi
--
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, 1 month