سؤال

أقوم بإعداد Maven لأخذ فصول Java المشروحة وإنتاج بعض DDL الذي يختلف حسب قاعدة البيانات. هل هناك طريقة أفضل للقيام بذلك؟ يبدو أنني يجب أن أكون قادرًا على تصفية الإدخال إلى المكون الإضافي HBM2DDL (كجزء من خط أنابيب) بدلاً من إخباره بالعمل على إخراج تصفية الموارد (والذي يجب عليّ بعد ذلك تصفية من جرة النهائية).

أقوم بتصفية ملف hibernate.cfg.xml الخاص بي لاستبدال خصائص البيئة بناءً على إعداد المطور المحلي:

  <build>
    <filters>
      <filter>${user.home}/datamodel-build.properties</filter>
    </filters>
    <resources><resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
    </resource></resources>
  </build>

ثم أقوم بتشغيل HBM2DDL على الإخراج

<plugin>
 <groupId>org.codehaus.mojo</groupId>
 <artifactId>hibernate3-maven-plugin</artifactId>
  ...
 <configuration>
   <componentProperties>
   <configurationfile>target/classes/com/myOrg/datamodel/hibernate.cfg.xml</configurationfile>
</plugin>

بعد ذلك ، يجب علي تصفية hibernate.cfg.xml من جرة الإنتاج الخاصة بي لأنني لا أرغب في شحن أي شيء يتعلق ببيئة Dev الداخلية الخاصة بي.

هل كانت مفيدة؟

المحلول

لدي نفس المشكلة وهنا كيف حللتها. يمكنني استخدام ملف قاعدة بيانات منفصلة. properties يحمل تفاصيل الاتصال ولا أقوم بتصفية أي من ملفات XML الخاصة بي.

يتم ترشيح ملف قاعدة البيانات المنفصل هذا. اختبار الموارد الموجودة في /src/main/test لا يتم وضعها في القطع الأثرية النهائية. ثم أخبر HBM2DDL أين أجدها على النحو التالي:

            <configuration>
                <components>
                    <component>
                        <name>hbm2ddl</name>
                        <implementation>jpaconfiguration</implementation>
                    </component>
                </components>
                <componentProperties>
                    <propertyfile>src/test/resources/database.properties</propertyfile>
                    <!-- Gives the name of the persistence unit as defined in persistence.xml -->
                    <persistenceunit>myapp-core</persistenceunit>
                    <!-- Tells the plugin to send the output to a file -->
                    <outputfilename>create-${database.vendor}-schema.sql</outputfilename>
                    <!-- Pretty Format SQL Code -->
                    <format>true</format>
                    <!-- Do not create tables automatically - other plug-ins will handle that -->
                    <export>false</export>
                    <!-- Do not print the DDL to the console -->
                    <console>false</console>
                </componentProperties>
            </configuration>

آمل أن يساعد ذلك على أي حال ....

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top