in-memorydb: إنشاء مخطط في "الإعداد ()" اختبار الوحدة: Netbeans (6.5.1) السبات (3) Junit (3)، HSQL (1.8)

StackOverflow https://stackoverflow.com/questions/1893737

سؤال

ما هي الخطوات اللازمة لإعداد DB في الذاكرة، وبناء المخطط تلقائيا باستخدام أداة "HBM2DL" الخاصة ب "HBM2DDL" في السبات ضمن إعداد Junit (3) "إعداد NetBeans 6.5.1؟ أنا لا أستخدم التعليقات التوضيحية السبات - مجرد ملف رسم الخرائط.

للحصول على الكود الفعلي، أريد استخدام قاعدة بيانات على القرص بالطبع. [هذا هو Junits يعيش حزمة "اختبار" منفصلة

لذلك أعتقد أن هذا هو الوصول إلى هناك:

  1. قم بإنشاء مشروع Java القياسي في Netbeans 6.5.1، أضف إلى مكتبة الريبر.
  2. قم بإنشاء ملف Pojos و Hibernate.cfg ورسم الخرائط السبات.
  3. انسخ ملف CFG ورسم الخرائط إلى حزمة الاختبار.

تبدو طريقة الإعداد مثل هذا:

 protected void setUp() throws Exception {
         Configuration config = new Configuration();
         config.configure();
         SchemaExport exporter;
         exporter=new SchemaExport(config);
         exporter.create(true, true);
    }
هل كانت مفيدة؟

المحلول

  1. قم بإنشاء مشروع Java القياسي في Netbeans 6.5.1، أضف إلى مكتبة الريبر.
  2. قم بإنشاء ملف Pojos و Hibernate.cfg ورسم الخرائط السبات.
  3. انسخ ملف CFG ورسم الخرائط إلى حزمة الاختبار.

الخطوط العريضة لحالة الاختبار تبدو وكأنها هذه:

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
...
public class DatabaseTest extends TestCase {
    private static Configuration config;
    private static SessionFactory sessionFactory;
    private static Session session;
...
    @Override
    protected void setUp() throws Exception {
         config = new Configuration();
         config.configure();
         SchemaExport exporter;
         exporter=new SchemaExport(config);
         exporter.create(true, true);
         sessionFactory = config.buildSessionFactory();
         session=sessionFactory.openSession();
    }
...
    @Override
    protected void tearDown() throws Exception {
        session.close();
    }
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top