Hi,
I'm using Hibernate/JPA and have an @Entity object called Order, pointing at a MySQL database using Hibernate's dynamic table generation i.e. generate tables at runtime for entities. When Hibernate creates the tables, it creates tables for all of my entities except the Order entity. If I rename the Order entity to something else e.g. StoreOrder, the store_order table is created no problem.
Furthermore, if I do this but then annotate the StoreOrder object to specify that the table it should create is called 'order' using @Table (name="order"), the table is no longer created.
I realise that order is a reserved word but is this the reason that it can't create the table? It seems odd given that the Hibernate docs uses an example of an entity called Order.
It doesn't look like a MySQL problem as I can manually create a table called order directly on the database.
Here's the relevant Order entity object definition...
@Entity
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
public class Order extends PersistentEntity {
... rest of POJO def...
}
...and the corresponding Persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
<persistence-unit name="store" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<mapping-file>conf/jpa/persistence-query.xml</mapping-file>
<!-- Entities -->
...other entities...
<class>ie.wtp.store.model.Order</class>
<class>ie.wtp.store.model.OrderItem</class>
<!-- Hibernate properties -->
<properties>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/store"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.username" value="root"/>
<property name="hibernate.connection.password" value=""/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
<property name="hibernate.query.factory_class"
value="org.hibernate.hql.classic.ClassicQueryTranslatorFactory"/>
<property name="hibernate.query.substitutions" value="true 1, false 0"/>
<property name="cache.provider_class" value="org.hibernate.cache.NoCacheProvider"/>
<property name="hibernate.max_fetch_depth" value="3"/>
<property name="hibernate.archive.autodetection" value="class"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
</properties>
</persistence-unit>
</persistence>
Any thoughts as to why this Order entity is not created but is created if I rename it to StoreOrder?
Cheers,
J :)