2016-08-14 4 views
0

私はJPAで初心者です。 エンティティのすべてのインスタンスを返すだけですmethod getAll。しかし、私がWARで私のプロジェクトを収集すると、私はこのエラーを受け取りますerror。 私はプロブレムが何か分かりません。私の主体や文脈ではおそらく問題です。 典型的なエンティティ:条件クエリを実行するためにTypedQueryのインスタンスを作成できません。

@Entity 
public class Currency { 
@Id 
@GeneratedValue(strategy = GenerationType.IDENTITY) 
private long id; 
private String name; 



public Currency() { 

} 

public long getId() { 
    return id; 
} 

public void setId(long id) { 
    this.id = id; 
} 

public String getName() { 
    return name; 
} 

public void setName(String name) { 
    this.name = name; 
} 

} 

がコンテキスト:

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:tx="http://www.springframework.org/schema/tx" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans.xsd 
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context.xsd 
    http://www.springframework.org/schema/tx 
    http://www.springframework.org/schema/tx/spring-tx.xsd"> 

<context:annotation-config/> 
<tx:annotation-driven/> 

<context:component-scan base-package="ru.stasdev"/> 

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
    <property name="prefix" value="/WEB-INF/pages/"/> 
    <property name="suffix" value=".jsp"/> 
</bean> 

<bean id="dataSource" 
     class="org.apache.commons.dbcp.BasicDataSource"> 
    <property name="driverClassName" value="com.mysql.jdbc.Driver"/> 
    <property name="url" value="jdbc:mysql://localhost:3306/mydbtest"/> 
    <property name="username" value="root"/> 
    <property name="password" value="root"/> 
    <property name="initialSize" value="3" /> 
    <property name="maxActive" value="10" /> 
</bean> 

<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> 
    <property name="dataSource" ref="dataSource"/> 
    <property name="packagesToScan" value="ru.stasdev.domain"/> 
    <property name="hibernateProperties"> 
     <props> 
      <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> 
      <prop key="hibernate.show_sql">true</prop> 
      <prop key="hibernate.format_sql">true</prop> 
     </props> 
    </property> 

</bean> 

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> 
    <property name="dataSource" ref="dataSource"/> 
    <property name="packagesToScan" value="ru.stasdev"/> 
    <property name="jpaVendorAdapter"> 
     <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> 
      <property name="showSql" value="true"/> 
      <property name="database" value="MYSQL"/> 
      <property name="databasePlatform" value="org.hibernate.dialect.MySQL5Dialect"/> 
     </bean> 
    </property> 
</bean> 

<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"> 
    <property name="basename" value="validation"/> 
</bean> 

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> 
    <property name="entityManagerFactory" ref="entityManagerFactory"/> 
</bean> 

答えて

-1

あなたは、一見JPA 1.0に対してコンパイルしていると呼び出されたメソッドがJPA 2.0+(すなわちEntityManager.createQuery(CriteriaQuery))です。したがって、コンパイルするJPA API jarをv2.0またはv2.1に修正する必要があります。

PS1。あなたがポストしたのはなぜコンパイラエラーとあなた自身のポストにあるエラーそのものでPOSTするのではないのですか(あなたが投稿したコードではなく、コンパイラエラーとはまったく関係ありません)。

PS2。なぜあなたはあなたの設定でいくつかのHibernate固有のものを持っている、私は分かりません。 EMFを作成するので、いくつかのHibernate SessionFactoryではなく、それを使用してください。

関連する問題