Hibernate won't create a specific table called "Product", even though it shows the create table command in the sql.
Category table gets created just fine...
These are classes ;
** BaseObject.java **
@MappedSuperclass
public class BaseObject implements Serializable
{
public static final long serialVersionUID = 1L;
@Id
@GeneratedValue
private Long id;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}
Category.java
@Entity
public class Category extends BaseObject {
private String name;
@OneToMany(fetch=FetchType.LAZY,mappedBy="category",orphanRemoval=true)
private List<Product> products;
@OneToOne(optional=true)
private Category parent;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<Product> getProducts() {
return products;
}
public void setProducts(List<Product> products) {
this.products = products;
}
public Category getParent() {
return parent;
}
public void setParent(Category parent) {
this.parent = parent;
}
}
Product.java
@Entity
public class Product extends BaseObject{
@ManyToOne
private Category category;
private String jargonCode;
private int order;
private String dataTableJson;
public Category getCategory() {
return category;
}
public void setCategory(Category category) {
this.category = category;
}
public String getDataTableJson() {
return dataTableJson;
}
public void setDataTableJson(String dataTableJson) {
this.dataTableJson = dataTableJson;
}
public String getJargonCode() {
return jargonCode;
}
public void setJargonCode(String jargonCode) {
this.jargonCode = jargonCode;
}
public int getOrder() {
return order;
}
public void setOrder(int order) {
this.order = order;
}
}
Spring Conf
<jee:jndi-lookup id="dataSource" jndi-name="${jdni.dataSource}"
expected-type="javax.sql.DataSource" />
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<list>
<value>com.dataCollector.pojo.Category</value>
<value>com.dataCollector.pojo.Product</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.showSql}</prop>
<prop key="hibernate.hbm2ddl.auto">${hibernate.action}</prop>
</props>
</property>
</bean>
The product won't get created. The strange thing is, it puts the create table command in the sql...
Hibernate: alter table Category drop foreign key FK_p6elut499cl32in8b8j8sy2n4
Hibernate: alter table Product drop foreign key FK_b7afq93qsn7aoydaftixggf14
Hibernate: drop table if exists Category
Hibernate: drop table if exists Product
Hibernate: create table Category (id bigint not null auto_increment, name varchar(255), parent_id bigint, primary key (id))
Hibernate: create table Product (id bigint not null auto_increment, dataTableJson varchar(255), jargonCode varchar(255), order integer not null, category_id bigint, primary key (id))
Hibernate: alter table Category add constraint FK_p6elut499cl32in8b8j8sy2n4 foreign key (parent_id) references Category (id)
Hibernate: alter table Product add constraint FK_b7afq93qsn7aoydaftixggf14 foreign key (category_id) references Category (id)
I really don't understand why.. I use MySQL server. And I've tried setting hibernate.hbm2ddl.auto to both create and create-drop. But nothing. Can anyone help me ?