[
http://opensource.atlassian.com/projects/hibernate/browse/HBX-524?page=co...
]
Marcio Carvalho commented on HBX-524:
-------------------------------------
Ok, Max, I am really sorry.
I forgot to mention that part of my change (item 1).
First of all, I apologyze to everybody that I could not find much time to build a patch of
my solution. Also I didn't believe that my work could be useful for anybody else than
my team, so I formatted the code in Eclipse making difficult to create a patch for my
changes (it included all the classes code just because of changes in line positions).
Another one of my changes was the insertion of the code below at the end of the
bindPrimaryKeyToProperties method (after the line containing
"rc.setIdentifier(id);"):
ForeignKey oneToOneFk = findOneToOneOwnerFK(rc);
if (oneToOneFk != null) {
Property prop =
bindOneToOne(rc, oneToOneFk.getReferencedTable(),
oneToOneFk, processed);
rc.addProperty(prop);
}
And I had to create the findOneToOneOwnerFK method used above. Here it goes:
protected ForeignKey findOneToOneOwnerFK(RootClass rc) {
ForeignKey found = null;
boolean isOneToOne = false;
Iterator foreignKeys = rc.getTable().getForeignKeyIterator();
while (!isOneToOne && foreignKeys.hasNext()) {
ForeignKey fk = (ForeignKey) foreignKeys.next();
isOneToOne = isOneToOne(fk);
if (isOneToOne)
found = fk;
}
return found;
}
So, this change will create a OneToOne reference in the child pointing to the OneToOne
owner.
It worked fine for me. Maybe the code I inserted at the end of the
bindPrimaryKeyToProperties method could have been placed in a better point. Feel free to
change.
There are some other helper methods that I created in the Cfg2HbmTool class to guide the
pojo generation.
Let me just prepare my lunch and I create a patch to these remaining few changes, and my
JPA annotated pojo template.
Regards,
Marcio.
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: Max Rydahl Andersen
Attachments: 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