كيف يمكنني اقتباس الجداول باستخدام hibernate3-maven-plugin HBM2DDL؟

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

سؤال

لديّ مشروع أقوم ببناءه مع Maven وأحتاج إلى إنشاء مخطط باستخدام أداة HBM2DDL من Hibernate3-Maven-Plugin.

أحتاج إلى إنشاء قاعدة بيانات بجدول يسمى ترتيب مثل الكلمة الرئيسية SQL ولا أعرف كيفية جعل Maven يقتبس من هذا الجدول عند إنشاء البرنامج النصي. لقد قمت بإجراء بحث ووجدت أن هناك خاصية في Hibernate لإخبار أداة HBM2DDL بهذا ، لكن لا يمكنني إخبار البرنامج المساعد لاستخدامه:

<property name="hbm2ddl.keywords">auto-quote</property>

إذا لم أقتبس من الجدول ، فإن HBM2DDL يولد نصًا:

create table Order (orderId varchar(36) not null, orderCode integer, customer varchar(36) not null, supplier varchar(36) not null, product varchar(36) not null, forecast float, dateRaised date not null, dateDispatched date, dateReceived date, quantityOrdered double precision not null, quantitySent double precision, primary key (orderId)) ENGINE=InnoDB;

لا يتم تجميع ذلك (بسبب خطأ في بناء الجملة واضح):

02:51:41,264 ERROR org.hibernate.tool.hbm2ddl.SchemaExport - Unsuccessful: create table Order (orderId varchar(36) not null, orderCode integer, customer varchar(36) not null, supplier varchar(36) not null, product varchar(36) not null, forecast float, dateRaised date not null, dateDispatched date, dateReceived date, quantityOrdered double precision not null, quantitySent double precision, primary key (orderId)) ENGINE=InnoDB
02:51:41,264 ERROR org.hibernate.tool.hbm2ddl.SchemaExport - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Order (orderId varchar(36) not null, orderCode integer, customer varchar(36) not' at line 1

هذا هو جزء من ملف pom.xml:

<configuration>
 <components>
  <component>
   <name>hbm2java</name>
   <implementation>annotationconfiguration</implementation>
   <outputDirectory>src/main/java</outputDirectory>
  </component>
  <component>
   <name>hbm2ddl</name>
   <implementation>annotationconfiguration</implementation>
   <outputDirectory>src/main/resources</outputDirectory>
  </component>
  <component>
   <name>hbm2doc</name>
   <implementation>annotationconfiguration</implementation>
   <outputDirectory>docs/html/hibernate</outputDirectory>
  </component>
 </components>
 <componentProperties>
  <create>true</create>
  <drop>true</drop>
  <configurationfile>src/main/resources/hibernate.cfg.xml</configurationfile>
  <propertyfile>src/main/resources/database.properties</propertyfile>
  <jdk5>true</jdk5>
  <outputfilename>amasbe_db.sql</outputfilename>
 </componentProperties>
</configuration>

أي نصائح أو مساعدة موضع تقدير حقًا.

شكرًا لك!

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

المحلول

afaik ، و hbm2ddl.keywords هي ميزة nhibernate ولا تدعمها السبات.

مع السبات ، سيتعين عليك اقتباس الاسم بنفسك:

@Entity
@Table(name="`Order`")
public class Order {
    ...
}

القسم ذي الصلة من الوثائق هو:

5.4. SQL مقتبسة معرفات

يمكنك إجبار السبات على اقتباس معرف في SQL الذي تم إنشاؤه عن طريق إرفاق اسم الجدول أو العمود في backticks في مستند رسم الخرائط. سوف تستخدم Hibernate نمط الاقتباس الصحيح لهجة SQL. عادة ما يكون هذا عروض أسعار مزدوجة ، لكن خادم SQL يستخدم قوسين ويستخدم MySQL backticks.

<class name="LineItem" table="`Line Item`">
    <id name="id" column="`Item Id`"/><generator class="assigned"/></id>
    <property name="itemNumber" column="`Item #`"/>
    ...
</class>

مراجع

نصائح أخرى

يمكن العثور على حل آخر للمشكلة هنا: https://forum.hibernate.org/viewtopic.php؟p=2409922

في الأساس ، كل ما تحتاجه هو استخلاص فئة استجابة لتوفير اسم الجدول/اسم العمود.

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

هتافات ، ترونج

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