-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: SchemaExport fails in 5.2 not finding ConfigurationService
PostPosted: Tue Nov 21, 2017 8:10 am 
Regular
Regular

Joined: Sun Aug 01, 2004 6:49 pm
Posts: 76
I try to migrate from 3.6 to 5.2 but unfortunately I have a problem in SchemaExport, it can not find the ConfigurationService in the registry. Might it be there is a bug in it?

For SchemaExport I need the Metadata, so first I construct it:
Code:
      URL resource = Hibere.class.getResource("/hibernate.cfg.xml");
      Configuration conf = new Configuration().configure(resource);
      ConfigurationServiceImpl confService = new ConfigurationServiceImpl(conf.getProperties());
      StandardServiceRegistryBuilder builder = conf.getStandardServiceRegistryBuilder();
      builder.addService(ConfigurationService.class, confService);
      builder.applySettings(conf.getProperties());
    Metadata metadata = new MetadataSources(serviceRegistry.build()).buildMetadata();

Then I hand over to SchemaExport:
Code:
      SchemaExport export = new SchemaExport();
      export.setOutputFile("schema.sql");
      EnumSet<TargetType> targetTypes = EnumSet.of(TargetType.SCRIPT);
      export.execute(targetTypes, Action.BOTH, metadata);


Then I receive following Exception, I check in a debugger and ConfigurationService is found in the Metadata as constructed above however within SchemaExport it is lost:
Code:
org.hibernate.service.UnknownServiceException: Unknown service requested [org.hibernate.engine.config.spi.ConfigurationService]
        at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
   at org.hibernate.tool.hbm2ddl.SchemaExport.buildTargetDescriptor(SchemaExport.java:329)
   at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:247)
   at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:228)


Top
 Profile  
 
 Post subject: Re: SchemaExport fails in 5.2 not finding ConfigurationService
PostPosted: Tue Nov 21, 2017 8:22 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1630
Location: Romania
The Configuration class is considered deprecated since there is a newer bootstrapping mechanism now:

Code:
final BootstrapServiceRegistryBuilder bsrb = new BootstrapServiceRegistryBuilder()
   .enableAutoClose();

final BootstrapServiceRegistry bsr = bsrb.build();

final StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder(bsr)
   .applySettings(properties())
   .build();

final MetadataSources metadataSources = new MetadataSources(serviceRegistry);

for (Class annotatedClass : entities()) {
   metadataSources.addAnnotatedClass(annotatedClass);
}

String[] resources = resources();
if (resources != null) {
   for (String resource : resources) {
      metadataSources.addResource(resource);
   }
}

final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder();
metadataBuilder.enableNewIdentifierGeneratorSupport(true);
metadataBuilder.applyImplicitNamingStrategy(ImplicitNamingStrategyLegacyJpaImpl.INSTANCE);

MetadataImplementor metadata = (MetadataImplementor) metadataBuilder.build();


Top
 Profile  
 
 Post subject: Re: SchemaExport fails in 5.2 not finding ConfigurationService
PostPosted: Tue Nov 21, 2017 8:46 am 
Regular
Regular

Joined: Sun Aug 01, 2004 6:49 pm
Posts: 76
Thanks for the hint, I changed but the error keeps the same, for me the problematic code is within SchemaExport, it looks like the Registry taken there is not correct or it is not provided correctly within MetadataBuildingOptions.
Code:
   public void execute(EnumSet<TargetType> targetTypes, Action action, Metadata metadata) {
      execute( targetTypes, action, metadata, ( (MetadataImplementor) metadata ).getMetadataBuildingOptions().getServiceRegistry() );
   }


Top
 Profile  
 
 Post subject: Re: SchemaExport fails in 5.2 not finding ConfigurationService
PostPosted: Tue Nov 21, 2017 10:09 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1630
Location: Romania
Check out the SchemaExportTest in Hibernate ORM code base.

You can fork the project, and run the test to see how it differs from your set up.


Top
 Profile  
 
 Post subject: Re: SchemaExport fails in 5.2 not finding ConfigurationService
PostPosted: Tue Nov 21, 2017 10:13 am 
Regular
Regular

Joined: Sun Aug 01, 2004 6:49 pm
Posts: 76
Thanks for the pointer. I found the problem in my code: a session factory was closed before issuing a destroy of all services in the registry. Looks a bit strange to me but ok.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.