Как я могу цитировать таблицы, используя 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>

Любые советы или помощь действительно ценится.

Спасибо!

Это было полезно?

Решение

Афайк, то hbm2ddl.keywords Функция Nhibernate и не поддерживается гибернатом.

С помощью гибернации вам придется процитировать имя себя:

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

Соответствующий раздел документации:

5.4. SQL цитируют идентификаторы

Вы можете заставить Hibernate процитировать идентификатор в сгенерированном SQL, приключив таблицу или имя столбца в Backticks в документе сопоставления. Hibernate будет использовать правильный стиль цитата для диалекта SQL. Обычно это двойные кавычки, но SQL Server использует кронштейны и 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