2016-07-12 3 views
0

私はMySqlデータベースから結果リストを取得する必要があるが、サーバー(wildfly 9)で実行するたびにこのアプリケーションで作業していますが、 dosen't exist.Hereは私のEJBのコードです:EJBと休止状態:テーブルが存在しない

@Stateless 
@LocalBean 
public class MessageService { 

    @PersistenceContext(unitName="primary") 
    EntityManager em; 

    @SuppressWarnings("unused") 
    public List<Message> customers = new ArrayList<Message>(); 

    public List<Message> findAll() { 
     customers= em.createQuery("select c from Message c").getResultList(); 
     //customers = query.getResultList(); 
     System.out.println(customers.size()); 
     return customers; 
    } 

を、これは私のエンティティである:

@Entity 
@NamedQuery(name="Message.findAll", query="SELECT m FROM Message m") 
public class Message implements Serializable { 
    private static final long serialVersionUID = 1L; 

    @Id 
    private int idMessage; 

    private String discriminateur; 

    private int numFenetre; 

    private String texte; 

、これが私のpersistence.xmlのです:

<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="primary"> 
     <!-- If you are running in a production environment, add a managed 
     data source, this example data source is just for development and testing! --> 
     <!-- The datasource is deployed as <EAR>/META-INF/MavenEar-ds.xml, you 
     can find it in the source at ear/src/main/application/META-INF/MavenEar-ds.xml --> 
     <jta-data-source>java:/mysql</jta-data-source> 
     <class>com.model.entities.Message</class> 
     <properties> 
     <!-- Properties for Hibernate --> 
     <!-- <property name="hibernate.hbm2ddl.auto" value="create-drop" />--> 
     <property name="hibernate.show_sql" value="false" /> 
     </properties> 
    </persistence-unit> 
</persistence> 

PS:私はデータベースへの激しいリンクにデータソースを設定しました。あなたのpersistence.xml

<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" /> 

に以下を追加し

Caused by: org.hibernate.exception.SQLGrammarException: could not extract ResultSet 
    at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:123) 
    at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49) 
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:126) 
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:112) 
    at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:91) 
    at org.hibernate.loader.Loader.getResultSet(Loader.java:2066) 
    at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1863) 
    at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1839) 
    at org.hibernate.loader.Loader.doQuery(Loader.java:910) 
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:355) 
    at org.hibernate.loader.Loader.doList(Loader.java:2554) 
    at org.hibernate.loader.Loader.doList(Loader.java:2540) 
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2370) 
    at org.hibernate.loader.Loader.list(Loader.java:2365) 
    at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:497) 
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:387) 
    at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:236) 
    at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1300) 
    at org.hibernate.internal.QueryImpl.list(QueryImpl.java:103) 
    at org.hibernate.jpa.internal.QueryImpl.list(QueryImpl.java:573) 
    at org.hibernate.jpa.internal.QueryImpl.getResultList(QueryImpl.java:449) 
    ... 126 more 
Caused by: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Table 'christina.message' doesn't exist 
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936) 
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985) 
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631) 
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723) 
    at com.mysql.jdbc.Connection.execSQL(Connection.java:3283) 
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1332) 
    at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1467) 
    at org.jboss.jca.adapters.jdbc.WrappedPreparedStatement.executeQuery(WrappedPreparedStatement.java:504) 
    at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:82) 
    ... 142 more 
+0

あなたはこのエラーを表示できますか?あなたはテーブルが存在しないと確信していますか?あなたは正しいデータベースに接続していると確信していますか? – teacurran

+0

テーブルが存在し、これが私のデータソース '\t jdbc:mysql:// localhost:3306/christina'のURLであることは明らかです。私はスタックトレースを追加します – MeknessiHamida

+0

@ちょっとしたおかげですでに問題が解決しました。回答の下で私のコメントを確認してください – MeknessiHamida

答えて

1

てみてください、私はそれがchristina.christina.messageを探しているかもしれないと思います。そうでなければ、エラーはテーブル "メッセージ"が見つからないと言うでしょう。エンティティにはどのような注釈が付きますか?カスタム命名戦略や方言を使用していますか?

+0

私はプロパティを追加しましたが、同じエラーです。私のエンティティには、それの上にある通常の '@ Entity'が付いています。それは – MeknessiHamida

+0

です。わかりません。私はまだそれが間違ったスキーマや何かにアクセスしようとしていると思われる。私は通常、mysqlのクエリログを有効にするので、すべてのクエリが表示されます。実際に正しいスキーマに当てられているかどうかを正確に伝える必要があります。 – teacurran

+0

ああ私の悪い点は、 'create-drop'がコメントする前にテーブルを削除してしまったので、私は愚かなことに本当に存在しないテーブルを探していました。私は今それを修正した。 – MeknessiHamida