错误: Error Code: 1064 Call: CREATE TABLE accountandpassword (id BIGINT NOT NULL, account VARCHAR(255), password VARCHAR(255), PRIMARY KEY (id)) Query: DataModifyQuery(sql=”CREATE TABLE accountandpassword (id BIGINT NOT NULL, account VARCHAR(255), password VARCHAR(255), PRIMARY KEY (id))”) 我用的是EJB3.0,已经实现了远程调用。 但是,EJB实现类中使用JPA方式对实体类进行管理。 数据库中没有表,据说可以在部署项目的时候会自动创建表。 实体bean: package com.mycompany; import java.io.Serializable; import java.util.Objects; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table; @Entity @Table(name = "accountandpassword") public class AccountAndPassword implements Serializable { private static final long serialVersionUID = 1L; @Id @Column(table = "accountandpassword", name = "id", length = 20) @GeneratedValue(strategy = GenerationType.AUTO) private Long id; @Column(table = "accountandpassword", name = "account", length = 255) private String account; @Column(table = "accountandpassword", name = "password", length = 255) private String password; public AccountAndPassword() { } public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getAccount() { return account; } public void setAccount(String account) { this.account = account; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } @Override public int hashCode() { int hash = 7; hash = 83 * hash + Objects.hashCode(this.id); hash = 83 * hash + Objects.hashCode(this.account); hash = 83 * hash + Objects.hashCode(this.password); return hash; } @Override public boolean equals(Object obj) { if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final AccountAndPassword other = (AccountAndPassword) obj; if (!Objects.equals(this.id, other.id)) { return false; } if (!Objects.equals(this.account, other.account)) { return false; } return true; } @Override public String toString() { return "AccountAndPassword{" + "id=" + id + ", account=" + account + ", password=" + password + ""}""; } } persistence .xml配置文件: <?xml version="1.0" encoding="UTF-8"?> <persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"> <persistence-unit name="Mypersistence" transaction-type="JTA"> <jta-data-source>db-pool-01-JNDI</jta-data-source> <exclude-unlisted-classes>false</exclude-unlisted-classes> <shared-cache-mode>NONE</shared-cache-mode> <properties> <property name="javax.persistence.schema-generation.database.action" value="create"/> </properties> </persistence-unit> </persistence> EJB接口实现类: package com.mycompany; import javax.ejb.Stateless; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; @Stateless public class MySession implements MySessionRemote{ @PersistenceContext(unitName = "Mypersistence") EntityManager em; @Override public void setAccountAndPassword(String account, String password) { AccountAndPassword aap = new AccountAndPassword(); aap.setAccount(account); aap.setPassword(password); em.persist(aap); } } |
|
40分 |
数据源配置中加上 dialect属性
<property name=”hibernate.dialect” value=”org.hibernate.dialect.MySQL5Dialect”/> |
加了以后还是会报错,但是报的错不一样了。 |
|
我的数据库连接池之前既可以ping通也可以flush通,我重装系统了,然后重新装的mysql,之前创建的连接池只可以ping通,但是不能flush,新创建一遍也是只能ping。 这是啥情况呢 |
|
OK,搞定了。
1、必须用mysql-connection-5.1.31.jar包 我放在了lib下。。。 |