Fornax-Platform
Forum

Hibernate Version 1.9.0 - Questions concerning schema export

View: New views
5 Messages — Rating Filter:   Alert me  

Hibernate Version 1.9.0 - Questions concerning schema export

by Klaus Mueller :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,
I tried to use the hibernate cartridge in conjunction with the feature "schemaExport" and now there are some
issues I wonder about.

First of all I get a MappingNotFoundException using both the features "schemaExport" and "pojo",
as long as I actually specify a pojo.package (like "pojo"). Here is a part of the output after running the workflow (don't
wonder about the expressionless package name):

...
12047 INFO  Configuration      - Reading mappings from file: .\src\generated\resources\de\fh\StudentImpl.hbm.xml
org.hibernate.MappingNotFoundException: file: .\src\generated\resources\de\fh\StudentImpl.hbm.xml not found
        at org.hibernate.cfg.Configuration.addFile(Configuration.java:307)
        at org.hibernate.cfg.Configuration.addFile(Configuration.java:293)
        at org.hibernate.tool.hbm2ddl.SchemaExport.main(SchemaExport.java:381)
        at org.fornax.cartridges.uml2.hibernate.SchemaExporter.invokeInternal(SchemaExporter.java:93)
        at org.openarchitectureware.workflow.lib.AbstractWorkflowComponent2.invoke(AbstractWorkflowComponent2.java:61)
        at org.openarchitectureware.workflow.container.ConditionalComponent.internalInvoke(ConditionalComponent.java:57)
        at org.openarchitectureware.workflow.container.ConditionalComponent.invoke(ConditionalComponent.java:39)
        at org.openarchitectureware.workflow.container.CompositeComponent.internalInvoke(CompositeComponent.java:129)
        at org.openarchitectureware.workflow.container.CompositeComponent.invoke(CompositeComponent.java:112)
        at org.openarchitectureware.workflow.container.CompositeComponent.internalInvoke(CompositeComponent.java:129)
        at org.openarchitectureware.workflow.container.CompositeComponent.invoke(CompositeComponent.java:112)
        at org.openarchitectureware.workflow.WorkflowRunner.executeWorkflow(WorkflowRunner.java:380)
        at org.openarchitectureware.workflow.WorkflowRunner.run(WorkflowRunner.java:261)
        at org.openarchitectureware.workflow.WorkflowRunner.main(WorkflowRunner.java:213)

In fact this file does not exist. After this I had a look at the file
org.fornax.cartridges.uml2.hibernate.SchemaExporter. There I found the method addHbmFiles, which contains the
following line:

String qn = srcRes +"/"+ Helper.getFQNPackagePath(entity)+"/" +entity.getName()+"Impl.hbm.xml";

In my case the method invocation Helper.getFQNPackagePath(entity) returns "de/fh". Therefore qn has the value
"./src/generated/resources/de/fh/StudentImpl.hbm.xml". The fact that I'm using a pojo package is not
taken into account. Of course this problem is not difficult to solve, as I can simply leave the pojo.package
empty or disable the pojo feature, but nevertheless I would like to know whether this behaviour serves a special
purpose or whether it is simply a small error.

To be able to continue testing the hibernate cartridge I left the pojo.package empty. As I want the cartridge to
actually export the script to the database, I adjusted the file hibernate.oaw
(org.fornax.cartridges.uml2.hibernate). My SchemaExport component now looks like this:

        <!--The SchemaExprot component. the schema export is invoced here-->
        <feature isSelected="schemaExport">
                <component id="SchemaExport"
                        class="org.fornax.cartridges.uml2.hibernate.SchemaExporter">
                        <modelSlot value="${hibernate.modelslot}" />
                        <srcRes value="${outlet.res.dir}" />
                        <textOnly value="false" />
                        <propertiesFile
                                value="${outlet.res.dir}/hibernate.properties" />
                </component>
        </feature>

As you can see I only added the textOnly-Element and set it to false. By default textOnly is set to true
and the documentation says that it means that the cartridge doesn't export to database.

After running the workflow again everything seems to work fine, but the schema is not exported to the
database. Following is a part of the output:

15641 INFO  ConditionalComponent - SchemaExporter(SchemaExport)
...
15875 INFO  Configuration      - Reading mappings from file: .\src\generated\resources\de\fh\StudentImpl.hbm.xml
16078 INFO  HbmBinder          - Mapping class: de.fh.StudentImpl -> TB_STUDENT
...
16469 INFO  SchemaExport       - Running hbm2ddl schema export
16469 INFO  SchemaExport       - writing generated schema to file: ./src/generated/resources/Data.ddl
16484 INFO  SchemaExport       - schema export complete


After this I had a look at the SchemaExport again. I was a bit surprised, due to the fact that inside
of the method invokeInternal, the parameter "--text" is set - not depending on the value of textOnly.
Moreover a part of the method is commented. This part would call the export method and actually
export the script to the database. Do I to get the wrong end of the stick or does the method invokeInternal
never export the script to the database (no matter what is specified in the SchemaExport component)?.
Please let me know what I got wrong.

At the moment I changed the implementation to call the export-method every time, as I want to export
the script to the database every time (at least at the moment, as there will be frequent changes at the beginning).
Is there another way to do this, did I miss to specify something or did I get another part wrong?

Thank you in advance.

Regards,
Klaus

Re: Hibernate Version 1.9.0 - Questions concerning schema export

by Darius Jockel :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello Klaus Müller,

Klaus Mueller wrote:
First of all I get a MappingNotFoundException using both the features "schemaExport" and "pojo",
as long as I actually specify a pojo.package (like "pojo").
The fact that I'm using a pojo package is not
taken into account. Of course this problem is not difficult to solve, as I can simply leave the pojo.package
empty or disable the pojo feature, but nevertheless I would like to know whether this behaviour serves a special purpose or whether it is simply a small error.
This is a 'small' error. I will fix it.

Klaus Mueller wrote:
To be able to continue testing the hibernate cartridge I left the pojo.package empty. As I want the cartridge to
actually export the script to the database, I adjusted the file hibernate.oaw
(org.fornax.cartridges.uml2.hibernate). My SchemaExport component now looks like this:

        <!--The SchemaExprot component. the schema export is invoced here-->
        <feature isSelected="schemaExport">
                <component id="SchemaExport"
                        class="org.fornax.cartridges.uml2.hibernate.SchemaExporter">
                        <modelSlot value="${hibernate.modelslot}" />
                        <srcRes value="${outlet.res.dir}" />
                        <textOnly value="false" />
                        <propertiesFile
                                value="${outlet.res.dir}/hibernate.properties" />
                </component>
        </feature>

As you can see I only added the textOnly-Element and set it to false. By default textOnly is set to true
and the documentation says that it means that the cartridge doesn't export to database.

After running the workflow again everything seems to work fine, but the schema is not exported to the
database. Following is a part of the output:

15641 INFO  ConditionalComponent - SchemaExporter(SchemaExport)
...
15875 INFO  Configuration      - Reading mappings from file: .\src\generated\resources\de\fh\StudentImpl.hbm.xml
16078 INFO  HbmBinder          - Mapping class: de.fh.StudentImpl -> TB_STUDENT
...
16469 INFO  SchemaExport       - Running hbm2ddl schema export
16469 INFO  SchemaExport       - writing generated schema to file: ./src/generated/resources/Data.ddl
16484 INFO  SchemaExport       - schema export complete


After this I had a look at the SchemaExport again. I was a bit surprised, due to the fact that inside
of the method invokeInternal, the parameter "--text" is set - not depending on the value of textOnly.
You are right. The flag textOnly is not used. The SchemaExport Class only generates a .ddl .

Klaus Mueller wrote:
Moreover a part of the method is commented.
There are problems configuring the SchemaExport by the Hibernate Config File "hibernate.cfg.xml" in some rare cases.
So we decided to configure the SchmaExport by hand by adding all classes manually.

Regards
Darius

Re: Hibernate Version 1.9.0 - Questions concerning schema export

by Darius Jockel :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Issue added. See:
http://fornax.itemis.de/jira/browse/CHB-104

Regards
Darius

Re: Hibernate Version 1.9.0 - Questions concerning schema export

by Klaus Mueller :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Darius Jockel wrote:
Issue added. See:
http://fornax.itemis.de/jira/browse/CHB-104

Regards
Darius
Hello Darius,
thank you for your quick answer and help. Would it be possible (for you or others that noticed the problems) to describe under which rare conditions there are problems with the schema export (in conjunction with the Hibernate config)? I'd be interested in this, as I want to use the cartridge and the schema export in one of my projects. Thank you very much in advance (regardless of whether you have time enough to describe it).

Regards,
Klaus

Re: Hibernate Version 1.9.0 - Questions concerning schema export

by Darius Jockel :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello Klaus.
Klaus Mueller wrote:
Would it be possible (for you or others that noticed the problems) to describe under which rare conditions there are problems with the schema export (in conjunction with the Hibernate config)? I'd be interested in this, as I want to use the cartridge and the schema export in one of my projects. Thank you very much in advance (regardless of whether you have time enough to describe it).
In some cases if you use composite keys. If you do not want to use composite key, this should be no problem.

Regards
Darius