Reputation: 4573
I have a jar file which has some mapping files I want to add then as mapping resource in hibernate.cfg.xml for that I added JAR in org.hibernate.cfg.Configuration..
Configuration cfg=new Configuration();
cfg.addJar(new File("C:\\Users\\amoghs\\.m2\\repository\\mkcl\\os\\personServiceBL\\1.0.1\\personServiceBL-1.0.1.jar"));
cfg.configure("hibernate.cfg.xml");
SchemaExport se=new SchemaExport(cfg);
se.setDelimiter("\n#-----------------------------------------------------------------------------------");
se.setOutputFile("E:\\ADFCreateScript.sql");
se.create(true,true);
and in hibernate.cfg.xml I added..
<mapping resource="org/mkcl/personservices/models/Person.hbm.xml" />
Person.hbm.xml this xml file is in jar file.
when i execute java application I got this exception...
Exception in thread "main" org.hibernate.InvalidMappingException: Could not parse mapping document from input stream
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processHbmXml(Configuration.java:3415)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processHbmXmlQueue(Configuration.java:3404)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3392)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1341)
at org.hibernate.cfg.Configuration.generateDropSchemaScript(Configuration.java:931)
at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:188)
at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:156)
at mkcl.accreditation.model.GenrateSchema.main(GenrateSchema.java:34)
Caused by: org.hibernate.PropertyNotFoundException: field [countryCode] not found on java.util.List
at org.hibernate.property.DirectPropertyAccessor.getField(DirectPropertyAccessor.java:182)
at org.hibernate.property.DirectPropertyAccessor.getField(DirectPropertyAccessor.java:174)
at org.hibernate.property.DirectPropertyAccessor.getGetter(DirectPropertyAccessor.java:197)
at org.hibernate.internal.util.ReflectHelper.getter(ReflectHelper.java:253)
at org.hibernate.internal.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:229)
at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(SimpleValue.java:326)
at org.hibernate.cfg.HbmBinder.createProperty(HbmBinder.java:2286)
at org.hibernate.cfg.HbmBinder.bindComponent(HbmBinder.java:1994)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2191)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2141)
at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:407)
at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:322)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:173)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processHbmXml(Configuration.java:3412)
Can anyone help me?
Upvotes: 0
Views: 1480
Reputation: 1158
If you add the entire jar to the Hibernate Configuration
, then all the mappings (*.hbm.xml) it contains are automatically added to the Configuration
. No need to add the following line in your hibernate.cfg.xml file :
<mapping resource="org/mkcl/personservices/models/Person.hbm.xml"/>
Upvotes: 1