2017-11-12 28 views
1

データベースにEmployeeエンティティを挿入しようとしています。私はJPAを使用しており、データベースはmysqlです。エンティティを挿入しようとすると、テーブルを作成する必要があります。テーブルを作成する必要はありません。 Entityは、注釈付きの名前を持つテーブルを自動的に作成します。以下の例外とコードを見つけてください。jpa mysqlテーブルが存在しません。autoGenerateが機能しません。

Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'gsq.articles' doesn't exist 
Error Code: 1146 
Call: CREATE TABLE articles (id INTEGER AUTO_INCREMENT NOT NULL, libelle VARCHAR(255), ENTREPRISE_id INTEGER, PRIMARY KEY (id)) 
Query: DataModifyQuery(sql="CREATE TABLE articles (id INTEGER AUTO_INCREMENT NOT NULL, libelle VARCHAR(255), ENTREPRISE_id INTEGER, PRIMARY KEY (id))") 
[EL Fine]: 2017-11-12 20:57:29.914--ServerSession(162116790)--Connection(578752466)--CREATE TABLE entreprise (id INTEGER AUTO_INCREMENT NOT NULL, libelle VARCHAR(255) UNIQUE, PRIMARY KEY (id)) 
[EL Fine]: 2017-11-12 20:57:29.919--ServerSession(162116790)--SELECT 1 
[EL Warning]: 2017-11-12 20:57:29.921--ServerSession(162116790)--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException 
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'gsq.entreprise' doesn't exist 
Error Code: 1146 
Call: CREATE TABLE entreprise (id INTEGER AUTO_INCREMENT NOT NULL, libelle VARCHAR(255) UNIQUE, PRIMARY KEY (id)) 
Query: DataModifyQuery(sql="CREATE TABLE entreprise (id INTEGER AUTO_INCREMENT NOT NULL, libelle VARCHAR(255) UNIQUE, PRIMARY KEY (id))") 
[EL Fine]: 2017-11-12 20:57:29.922--ServerSession(162116790)--Connection(578752466)--CREATE TABLE users (ID BIGINT AUTO_INCREMENT NOT NULL, password VARCHAR(255), type VARCHAR(255), username VARCHAR(255) UNIQUE, PRIMARY KEY (ID)) 
[EL Fine]: 2017-11-12 20:57:29.927--ServerSession(162116790)--SELECT 1 
[EL Warning]: 2017-11-12 20:57:29.929--ServerSession(162116790)--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException 
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'gsq.users' doesn't exist 
Error Code: 1146 
Call: CREATE TABLE users (ID BIGINT AUTO_INCREMENT NOT NULL, password VARCHAR(255), type VARCHAR(255), username VARCHAR(255) UNIQUE, PRIMARY KEY (ID)) 
Query: DataModifyQuery(sql="CREATE TABLE users (ID BIGINT AUTO_INCREMENT NOT NULL, password VARCHAR(255), type VARCHAR(255), username VARCHAR(255) UNIQUE, PRIMARY KEY (ID))") 
[EL Fine]: 2017-11-12 20:57:29.93--ServerSession(162116790)--Connection(578752466)--ALTER TABLE articles ADD CONSTRAINT FK_articles_ENTREPRISE_id FOREIGN KEY (ENTREPRISE_id) REFERENCES entreprise (id) 
[EL Fine]: 2017-11-12 20:57:29.935--ServerSession(162116790)--SELECT 1 
[EL Warning]: 2017-11-12 20:57:29.936--ServerSession(162116790)--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException 
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'gsq.articles' doesn't exist 
Error Code: 1146 
Call: ALTER TABLE articles ADD CONSTRAINT FK_articles_ENTREPRISE_id FOREIGN KEY (ENTREPRISE_id) REFERENCES entreprise (id) 
Query: DataModifyQuery(sql="ALTER TABLE articles ADD CONSTRAINT FK_articles_ENTREPRISE_id FOREIGN KEY (ENTREPRISE_id) REFERENCES entreprise (id)") 
[EL Fine]: 2017-11-12 20:57:30.035--ServerSession(162116790)--Connection(578752466)--SELECT id, libelle FROM entreprise 
[EL Fine]: 2017-11-12 20:57:30.035--ServerSession(162116790)--SELECT 1 
[EL Warning]: 2017-11-12 20:57:30.035--UnitOfWork(1734860123)--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException 
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'gsq.entreprise' doesn't exist 
Error Code: 1146 
Call: SELECT id, libelle FROM entreprise 
Query: ReadAllQuery(referenceClass=Entreprise sql="SELECT id, libelle FROM entreprise") 
Exception in thread "AWT-EventQueue-0" javax.persistence.RollbackException: Transaction rolled back because transaction was set to RollbackOnly. 
    at org.eclipse.persistence.internal.jpa.transaction.EntityTransactionImpl.commitInternal(EntityTransactionImpl.java:92) 
    at org.eclipse.persistence.internal.jpa.transaction.EntityTransactionImpl.commit(EntityTransactionImpl.java:63) 
    at controlleur.Executerequest.closeEntityManager(Executerequest.java:73) 
    at frame.ArticlesFram.MajComBox(ArticlesFram.java:385) 
    at frame.ArticlesFram.<init>(ArticlesFram.java:53) 
    at frame.ArticlesFram$13.run(ArticlesFram.java:501) 
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311) 
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756) 
    at java.awt.EventQueue.access$500(EventQueue.java:97) 
    at java.awt.EventQueue$3.run(EventQueue.java:709) 
    at java.awt.EventQueue$3.run(EventQueue.java:703) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76) 
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:726) 
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201) 
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116) 
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105) 
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) 
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) 
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82) 

persistence.xmlの

<?xml version="1.0" encoding="UTF-8"?> 
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"> 
    <persistence-unit name="GSQPU" transaction-type="RESOURCE_LOCAL"> 
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> 
    <class>entities.Articles</class> 
    <class>entities.Entreprise</class> 
    <class>entities.Users</class> 
    <properties> 
     <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/gsq"/> 
     <property name="javax.persistence.jdbc.password" value=""/> 
     <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/> 
     <property name="javax.persistence.jdbc.user" value="root"/> 
     <property name="eclipselink.logging.level.sql" value="FINE"/> 
     <property name="eclipselink.logging.parameters" value="true"/> 
     <property name="eclipselink.ddl-generation" value="create-tables"/> 
    </properties> 
    </persistence-unit> 
</persistence> 

Artcileエンティティ

@Entity 
@Table(name = "articles") 
@XmlRootElement 
@NamedQueries({ 
    @NamedQuery(name = "Articles.findAll", query = "SELECT a FROM Articles a"), 
    @NamedQuery(name = "Articles.findById", query = "SELECT a FROM Articles a WHERE a.id = :id"), 
    @NamedQuery(name = "Articles.findByLibelle", query = "SELECT a FROM Articles a WHERE a.libelle = :libelle")}) 
public class Articles implements Serializable { 

    private static final long serialVersionUID = 1L; 
    @Id 
    @GeneratedValue(strategy = GenerationType.IDENTITY) 
    @Basic(optional = false) 
    @Column(name = "id") 
    private Integer id; 


    @Column(name = "libelle") 
    private String libelle; 
    @ManyToOne 
    private Entreprise entreprise; 



    public Articles() { 
    } 

    public Articles(Integer id) { 
     this.id = id; 
    } 


} 
+0

に接続することによってそれを解決しました。 JPA/EclipseLinkの外部に接続して、何がうまくいかないのかを診断し、何か答えを試してみてください。https://stackoverflow.com/questions/7759170/mysql-table-doesnt-exist-but-it-does-orit - – Chris

+0

これは私の問題でした。他のデータベースに接続して解決しました。 –

答えて

0

私はEclipseLinkをして動作しますが、いくつかの例をチェックし、すべてが4つのプロパティそれぞれの下に言及していることが確認できていません時間:

<property name="eclipselink.ddl-generation" value="drop-and-create-tables"/> 
<property name="eclipselink.create-ddl-jdbc-file-name" value="createDDL_ddlGeneration.jdbc"/> 
<property name="eclipselink.drop-ddl-jdbc-file-name" value="dropDDL_ddlGeneration.jdbc"/> 
<property name="eclipselink.ddl-generation.output-mode" value="both"/> 

が原因である可能性がありますか?

+0

create tables文がログに表示されているので、テーブルを作成しようとしています。 – Chris

0

問題はJPAでデータベースレベルであったとない私はあなたのデータベースではなく、JPA/EclipseLinkので問題を抱えている別のデータベースTHX

関連する問題