I am using Hibernate / JPA and have an @Entity object called Order pointing to a MySQL database using a dynamic Hibernate table, i.e. generates runtime tables for objects. When Hibernate creates tables, it creates tables for all my objects except the Order entity. If I rename the Order object to something else, for example. StoreOrder, the store_order table is not created.
Also, if I do this, but then annotate the StoreOrder object to indicate that the table that it should create is called βorderβ using @Table (name = "order"), the table is no longer created.
I understand that an order is a reserved word, but is this the reason that it cannot create a table? It seems strange given that Hibernate docs uses an example object called Order.
This doesn't seem to be a MySQL problem, since I can manually create a table called order directly in the database.
Here is the corresponding definition of the order entity object ...
@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> ...other entities... <class>ie.wtp.store.model.Order</class> <class>ie.wtp.store.model.OrderItem</class> <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 on why this order object is not created, but created if I rename it to StoreOrder?
Greetings
J :)
java mysql orm hibernate jpa
Jay shark
source share