मैं एक मुख्य विधि SchemaUpdate का उपयोग कर सांत्वना क्या टेबल बदल/बनाने के लिए पर प्रदर्शित करने के लिए है और यह मेरी हाइबरनेट परियोजना में ठीक काम करता है:एक जेपीए persistence.xml के साथ Hibernate SchemaUpdate कक्षा का उपयोग कैसे करें?
public static void main(String[] args) throws IOException {
//first we prepare the configuration
Properties hibProps = new Properties();
hibProps.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("jbbconfigs.properties"));
Configuration cfg = new AnnotationConfiguration();
cfg.configure("/hibernate.cfg.xml").addProperties(hibProps);
//We create the SchemaUpdate thanks to the configs
SchemaUpdate schemaUpdate = new SchemaUpdate(cfg);
//The update is executed in script mode only
schemaUpdate.execute(true, false);
...
मैं एक जेपीए परियोजना में इस कोड को पुन: उपयोग करना चाहते हैं, कोई hibernate.cfg.xml फ़ाइल नहीं है (और नहीं .properties फ़ाइल), लेकिन एक persistence.xml फ़ाइल (जेपीए spec द्वारा निर्दिष्ट मेटा-आईएनएफ निर्देशिका में autodetected)।
मैं इस बहुत आसान अनुकूलन की कोशिश की,
Configuration cfg = new AnnotationConfiguration();
cfg.configure();
लेकिन यह है कि अपवाद के साथ विफल रहा है।
Exception in thread "main" org.hibernate.HibernateException: /hibernate.cfg.xml not found
क्या किसी ने ऐसा किया है? धन्यवाद।
प्ले फ्रेमवर्क पर, मैं Ejb3Configuration पर getHibernateConfiguration() का उपयोग करें और मैं एक "कोई प्रदान की डेटा स्रोत" प्राप्त करते हैं। मैं एक कनेक्शन (DB.datasource.getConnection() खेलने पर कैसे प्रदान कर सकता हूं)? –