Java org.hibernate.exception.sqlgrammareexception:Table';XXX和x27;不';不存在
我将JPA与hibernate实现结合使用。 我的项目如下所示: 我的pom.xml中的依赖项Java org.hibernate.exception.sqlgrammareexception:Table';XXX和x27;不';不存在,java,mysql,hibernate,jpa,Java,Mysql,Hibernate,Jpa,我将JPA与hibernate实现结合使用。 我的项目如下所示: 我的pom.xml中的依赖项 <dependencies> <!-- JUNIT --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</ver
<dependencies>
<!-- JUNIT -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- MYSQL CONNECTOR -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.9</version>
</dependency>
<!-- HIBERNATE -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.1.6.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.1.6.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.5.5-Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.common</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<version>4.0.4.Final</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.7</version>
</dependency>
</dependencies>
我知道数据库中不存在该表,但当我运行应用程序时,我希望在数据库中创建该表
主要方法是:
public static void main(String[] argv) {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("manager");
EntityManager em = emf.createEntityManager();
EntityTransaction transac = em.getTransaction();
transac.begin();
em.persist(new Person("mahmoud", "lotfi", "morroco"));
transac.commit();
em.close();
emf.close();
}
实体人:
@Entity
@表(name=“Person”)
公共类Person实现可序列化{
private static final long serialVersionUID = 4717398914745522714L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
@Column(name = "last_name", length = 50, nullable = false, unique = false, updatable = true)
private String lastname;
@Column(name = "first_name", length = 50, nullable = false, unique = false, updatable = true)
private String firstname;
@Column(name = "country", length = 50, nullable = true, unique = false, updatable = true)
private String country;
public Person(String lastname, String firstname, String country) {
super();
this.lastname = lastname;
this.firstname = firstname;
this.country = country;
}
public Person() {
}
// GETTERS AND SETTERS ....
解决方案摘要 要让
Hibernate
在persistence.xml
的初始化过程中创建表,必须定义属性Hibernate.hbm2ddl.auto
。(请参阅:)
属性必须设置为
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"
@次优:是的,我知道,但我不知道她为什么没有创建它的alrady existe,PropertiesOrry中的第7行。我一定忽略了两次。:-(请看这里(),可能是解决方案。非常感谢,先生,这是解决方案:)
private static final long serialVersionUID = 4717398914745522714L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
@Column(name = "last_name", length = 50, nullable = false, unique = false, updatable = true)
private String lastname;
@Column(name = "first_name", length = 50, nullable = false, unique = false, updatable = true)
private String firstname;
@Column(name = "country", length = 50, nullable = true, unique = false, updatable = true)
private String country;
public Person(String lastname, String firstname, String country) {
super();
this.lastname = lastname;
this.firstname = firstname;
this.country = country;
}
public Person() {
}
// GETTERS AND SETTERS ....
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect"
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"