Java 冬眠赢了';即使在sql中显示,也不能创建表
Hibernate不会创建一个名为“Product”的特定表,即使它在sql中显示了CREATETABLE命令 类别表创建得很好 这些是课程 **BaseObject.java**Java 冬眠赢了';即使在sql中显示,也不能创建表,java,mysql,spring,hibernate,Java,Mysql,Spring,Hibernate,Hibernate不会创建一个名为“Product”的特定表,即使它在sql中显示了CREATETABLE命令 类别表创建得很好 这些是课程 **BaseObject.java** @MappedSuperclass public class BaseObject implements Serializable { public static final long serialVersionUID = 1L; @Id @GeneratedValue private Long id; pu
@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;
}
}
@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;
}
}
春季形态
<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>
我真的不明白为什么。。我使用MySQL服务器。
我尝试将hibernate.hbm2ddl.auto设置为create和createdrop。但什么都没有。有人能帮我吗?尝试更改“order”列名,这是一个保留字,形式上sql是正确的,因为我在调用列“user”而不是“userId”时遇到了类似的问题。这可能是由于使用了不正确的方言造成的问题。能否指定MYSQL服务器使用的方言。org.hibernate.dialogue.mysqldialogue看起来不错。。但仍然要看看这是否有助于查看您在配置文件中指定的db用户的权限。对我来说,这不是Hibernate的问题,这是一些错误的相关连接或相关MYSQL。谢谢。但这是订单栏造成的..哈!你是对的。。我从没想过会是这样。。非常感谢。
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)