错误:
Internal Exception: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'OPTION SQL_SELECT_LIMIT=DEFAULT' at line 1
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);
}
}
------解决思路----------------------
数据源配置中加上 dialect属性
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>