-1

I have been searching everywhere, but could not find where exactly hibernate uses HttpURLConnection. Theoretically I think it uses for its back end connectivity.

My issue is I have a java agent which instruments HttpURLConnection to set a header every time it gets called. I want to use that agent with my Hibernate application but it fails. When I don't use my Java Agent it works perfectly fine. Even if the JAVA Agent is changed to print only some codes that works fine. But when I try to add a header to it, it fails giving an exception -

Exception in thread "main" org.hibernate.HibernateException: Could not parse configuration: hibernate.cfg.xml
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2163)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:2075)
    at com.javapapers.App.test(App.java:101)
    at com.javapapers.App.main(App.java:19)
Caused by: org.dom4j.DocumentException: null Nested exception: null
    at org.dom4j.io.SAXReader.read(SAXReader.java:484)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2155)
    ... 3 more

I searched and tried all the way to get rid of this, but failed.

JAVA Agent Code to instrument:

ctConstructor.insertAfter("System.out.println(10);"
+ "setRequestProperty(\"testHeader\",\"NewHeader\");");
Hash
  • 4,647
  • 5
  • 21
  • 39
s s
  • 286
  • 2
  • 14
  • Exception does not say anything about `HTTPURLConnection`: *Could not parse configuration: hibernate.cfg.XML* – Jens May 29 '18 at 06:29
  • That is what my hit and try test says.. I have written there , Once i remove "setRequestProperty(\"testHeader\",\"NewHeader\") this it works fine. But when i try and add this it does not work.. – s s May 29 '18 at 06:32
  • Check hibernate.cfg.xml `Caused by: org.dom4j.DocumentException: null Nested exception: null` – Govinda Sakhare May 29 '18 at 06:32
  • Yes i checked and tried all the way to get rid of that .. But untill i remove my java agent it thows that Null. – s s May 29 '18 at 06:33

1 Answers1

0

In your case hibernate could be pulling the DTD from the internet. FYI Default DOCTYPE,

<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
    "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

You can change your XML DOCTYPE to pull the DTD from the classpath

<!DOCTYPE hibernate-configuration SYSTEM 
"classpath://org/hibernate/hibernate-configuration-3.0.dtd">
Govinda Sakhare
  • 5,009
  • 6
  • 33
  • 74
  • earlier ,I tried this too . it didn't work. But will try again, just inCase – s s May 29 '18 at 06:51
  • if you are using the `build` system, I suggest you to trigger the clean build. – Govinda Sakhare May 29 '18 at 06:52
  • it does not work.Throws an Exception in thread "main" org.hibernate.InvalidMappingException: Unable to read XML – s s May 29 '18 at 06:52
  • have you replaced `hibernate-configuration-3.0.dtd` with the appropriate hibernate version on your classpath? – Govinda Sakhare May 29 '18 at 06:54
  • yes. I tried.Even after clean build. its not working.it throwing an Exception in thread "main" org.hibernate.HibernateException: hibernate.cfg.xml not found. I am new to Hibernate. – s s May 29 '18 at 06:59