java - Hibernate dynamic entity model -


i creating java application utilizes jpa annotated model - core model -. on top of these entities, @ runtime, add jar file external source contains other jpa classes definitions , mappings. imported archive might change class structure , mappings, application's duty refresh entire schema when changed.

however, when trying add jar hibernate configuration, a

  org.hibernate.service.spi.serviceexception: unable create requested service [org.hibernate.engine.jdbc.env.spi.jdbcenvironment] 

the inner exception related hibernate dialect:

org.hibernate.hibernateexception: access dialectresolutioninfo cannot null when 'hibernate.dialect' not set 

however, sure have specified hibernate.dialect property in persistence.xml file. below code using in application:

org.hibernate.cfg.configuration cfg = new org.hibernate.cfg.configuration(); cfg.addjar(new file("path/to/jar.jar")); cfg.buildsessionfactory(); 

what doing wrong?

also, please tell me if find approach create dynamically updateable schema shared between multiple applications?

i managed solve problem. main point that, when using entitymanagerfactory (the jpa api), hibernate persistence provider reads persistence.xml configuration files , loads persistence units specified therein.

however, using hibernate api configuration, hibernate not read persistence.xml files, 1 have explicitly specify aspects such dialect, connection parameters etc in hibernate.cfg.xml file.

however, managed work around issue. indeed, in dynamically loaded jar file, 1 must export folders (the meta-inf especially) , configure persistence.xml file in there too. however, naming 2 persistence units same, corresponding classes not merged , neither other properties. default, hibernate load first found persistence unit , treat identically-named ones different. so, created more flexible core schema allows access multiple persistence units, while caching them in similar dictionaries. consequently, each schema in application, load corresponding persistence unit while storing of them in dictionary-style container, allowing application notified should changes occur underlying jar file.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -