Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address #511 Support for import.sql and related property in JPA with no persistence.xml #538

Closed
wants to merge 1 commit into from

Conversation

emmanuelbernard
Copy link
Member

Code is OK I think.
Doc is done.

There is an annoying warning raised by Hibernate when no import.sql is present.
We would need #406 to address that.

Test is partial: A proper testing strategy can be done once #534 is fixed.

Should we merge and add a follow up?

docs/src/main/asciidoc/hibernate-orm-guide.adoc Outdated Show resolved Hide resolved
docs/src/main/asciidoc/hibernate-orm-guide.adoc Outdated Show resolved Hide resolved
* specify the location of a load script.
* The location specified in this property is relative to the root of the persistence unit.
*/
@ConfigProperty(name="sql-load-script-source")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we can have some properties with - and others with _ (see show_sql just above). We must be consistent in what casing we use. Also, why not shorter such as importFile (or import-file or import_file depending on what style we standardise on)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same remark here about the convention. I checked the existing code and for now it's a big mix of dash or camel case. We need to decide about this and stick to it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason was to ressemble the underlying property name of the library or standard.
If we think it's not useful enough, then we can invent our own names. Thoughts? @FroMage @gsmet

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sql_script / sql-script ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Sanne those would work for me.

String file = hibernateOrmConfig
.flatMap(c -> c.sqlLoadScriptSource)
.orElse("/import.sql"); //default Hibernate ORM file imported
desc.getProperties().setProperty(AvailableSettings.HBM2DDL_LOAD_SCRIPT_SOURCE, file);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we check for the file's existence and not set the property if it does not exist? This would avoid the warning, no?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would have been my intention too but I'm wondering if you have enough context to load the file properly?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 we need to check for its existance, as we'll also need to register the resource for being included in the native binary - or don't register it if there's no file.

Currently that's done in a different block, IMO we should check once and make good use of it.

Also the warning about the file not existing should be triggered here, not at "final boot"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, sort of.

Copy link
Member

@gsmet gsmet Jan 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be:

if (loadScriptPath.isPresent()) {
    desc.getProperties().setProperty(AvailableSettings.HBM2DDL_LOAD_SCRIPT_SOURCE, file);
}

?

I think that's why you still have the Hibernate warning. I can fix it myself and merge, just wanted to check you didn't have a good reason to not do that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, fixed. Thanks Guillaume. I pushed a new version.

@emmanuelbernard
Copy link
Member Author

emmanuelbernard commented Jan 17, 2019

@gsmet @Sanne @FroMage

I've pushed a new version that

  • fix the doc type
  • check the presence of the file (default or not)
  • throw exception if the explicitly set file is not present
  • enlist the resource for both SubstrateVM and HotDeployment on change
  • added a SubstrateVM native test (resources visibility)

We still have the following pending problems and questions to address

  • more tests once ShamrockUnitTest works better
  • decide to keep the property name consistent with JPA or move to another one and be Shamrock consistent
  • decide for /import.sql vs META-INF/import.sql: all shamrock resources seem to be under META-INF so maybe we should align
  • I could not fix the Hibernate ORM warning because when there is no explicit file set, Hibernate ORM looks for /import.sql and WARN. At this stage the fix has to be in Hibernate ORM or filtered out I think. I could add an empty file to stop that WARN but there will be some output from the Hibernate logs anyways.

@FroMage
Copy link
Member

FroMage commented Jan 17, 2019

Just opened #550 to fix the config name issue before it becomes evident we're just making shit up and throwing it together ;)

@Sanne
Copy link
Member

Sanne commented Jan 17, 2019

Toning down the WARN:

+1 to defer additional tests

I'd go for custom (shorter?) property names rather than the JPA ones, so to give us some flexibility on their exact semantics without confusing the users about them.

About "decide for /import.sql vs META-INF/import.sql" .. my instinct is that in this case it doesn't belong in META-INF but I should find some proper guidance about such stuff. I'll send an email to the mailing list about finding some consistency on that.

Alternative file name can be set with
shamrock.hibernate.sql-load-script-source
@Sanne
Copy link
Member

Sanne commented Jan 17, 2019

So the WARN is gone after the latest changes.

I still have this one though, when there's no script to run (and none configured):

INFO [o.h.t.s.i.SchemaCreatorImpl] (main) HHH000476: Executing import script 'org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl@1ad777f'

I'll get rid of it, since we're on the topic..

@Sanne
Copy link
Member

Sanne commented Jan 17, 2019

Actually in native I get both following lines !?

2019-01-17 16:34:13,772 venti rest-http-crud-shamrock-1.0.0.Alpha1-SNAPSHOT-runner[8084] INFO [o.h.t.s.i.SchemaCreatorImpl] (main) HHH000476: Executing import script 'ScriptSourceInputFromUrl(resource:import.sql)'
2019-01-17 16:34:13,779 venti rest-http-crud-shamrock-1.0.0.Alpha1-SNAPSHOT-runner[8084] INFO [o.h.t.s.i.SchemaCreatorImpl] (main) HHH000476: Executing import script 'org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl@16b8c38'

@Sanne
Copy link
Member

Sanne commented Jan 17, 2019

@Sanne
Copy link
Member

Sanne commented Jan 17, 2019

Merged this one. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants