1

我不断收到消息

 java.lang.NoSuchMethodError: org.apache.cassandra.thrift.TBinaryProtocol: method <init>(Lorg/apache/thrift/transport/TTransport;)V not found
 at com.impetus.client.cassandra.schemamanager.CassandraSchemaManager.initiateClient(CassandraSchemaManager.java:446)
at com.impetus.kundera.configure.schema.api.AbstractSchemaManager.exportSchema(AbstractSchemaManager.java:101)
at com.impetus.client.cassandra.schemamanager.CassandraSchemaManager.exportSchema(CassandraSchemaManager.java:138)
at com.impetus.kundera.configure.SchemaConfiguration.configure(SchemaConfiguration.java:172)
at com.impetus.kundera.configure.ClientMetadataBuilder.buildClientFactoryMetadata(ClientMetadataBuilder.java:45)
at com.impetus.kundera.persistence.EntityManagerFactoryImpl.configureClientFactories(EntityManagerFactoryImpl.java:352)
at com.impetus.kundera.persistence.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:116)
at com.impetus.kundera.KunderaPersistence.createEntityManagerFactory(KunderaPersistence.java:83)
at com.impetus.kundera.KunderaPersistence.createContainerEntityManagerFactory(KunderaPersistence.java:65)

每当我尝试运行我的 Java Spring MVC 3.2 项目时。我正在尝试使用 Kundera 从 Spring WebApp 连接到我在我的机器上安装的 Apache Cassandra 1.2.8。我在项目的 pom.xml 文件中包含了以下依赖项:

  1. scale7-pelops(1.3-1.1.x)
  2. cassandra-all 和 cassandra-clientutil (1.2.8)
  3. 昆德拉核心和昆德拉卡桑德拉 (2.6)

我的 Spring 项目使用无 XML 配置 (Java Config) 和 JPA,而 kundera 的 persistence.xml 位于 {PROJECT}/src/main/resources/META-INF 下,以便在部署期间位于类路径的基础。我的 persistence.xml 看起来像:

    <persistence 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"
        version="2.0">
        <persistence-unit name="cassandra_pu">
            <provider>com.impetus.kundera.KunderaPersistence</provider> 
            <class>org.tutiworks.orm.Role</class>
            <class>org.tutiworks.orm.User</class>   
            <properties>            
                <property name="kundera.nodes" value="localhost"/>
                <property name="kundera.port" value="9160"/>
                <property name="kundera.keyspace" value="afrikana"/>
                <property name="kundera.dialect" value="cassandra"/>
                <property name="kundera.ddl.auto.prepare" value="update"/>
                <property name="kundera.client.lookup.class" value="com.impetus.client.cassandra.pelops.PelopsClientFactory" />
                <property name="kundera.cache.provider.class" value="com.impetus.kundera.cache.ehcache.EhCacheProvider"/>
                <property name="kundera.cache.config.resource" value="/ehcache-cassandra.xml"/>                 
            </properties>       
        </persistence-unit>
    </persistence>

创建 entityManager 的配置类如下所示:

            @Configuration
    public class SpringDataConfig extends WebMvcConfigurerAdapter{

        @Autowired
        private Environment env;

        @Value("${kundera.nodes}") private String node;
        @Value("${kundera.port}") private String port;
        @Value("${kundera.keyspace}") private String keyspace;
        @Value("${kundera.dialect}") private String dialect;
        @Value("${kundera.ddl.auto.prepare}") private String dbGenerator;
        @Value("${kundera.cache.provider.class}") private String cacheClass;
        @Value("${kundera.client.lookup.class}") private String lookupClass;
        @Value("${kundera.cache.config.resource}") private String configResource;
        @Value("${persistence.unit.name}") private String persistenceUnitName;

        @Bean
        public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
            LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
            em.setPersistenceUnitName(persistenceUnitName);
            return em;
        }

        @Bean
        public PersistenceExceptionTranslationPostProcessor exceptionTranslation() {
            return new PersistenceExceptionTranslationPostProcessor();
        }
    }

下面的类展示了如何使用持久化上下文。

        public abstract class GenericDAO< T extends Serializable > {

           private Class<T> clazz;

           @PersistenceContext
           EntityManager entityManager;

           protected void setClazz( Class<T> clazzToSet ){
              this.clazz = clazzToSet;
           }

           public T findOne( String id ){
              return this.entityManager.find( this.clazz, id );
           }

           @SuppressWarnings("unchecked")
           public List< T > findAll(){
              return this.entityManager.createQuery( "from " + this.clazz.getName() )
               .getResultList();
           }

           public void save( T entity ){
              this.entityManager.persist( entity );
           }

           public void update( T entity ){
              this.entityManager.merge( entity );
           }

           public void delete( T entity ){
              this.entityManager.remove( entity );
           }
           public void deleteById( String entityId ){
              T entity = this.findOne( entityId );

              this.delete( entity );
           }
        }

在 Apache Cassandra 安装中映射到列族的 ORM 示例如下所示。

      @XmlRootElement(name = "Role")
    @Entity(name="Role")
    @Table(name = "roles", schema = "afrikana@cassandra_pu")
    public class Role implements Serializable {

        private static final long serialVersionUID = 9127322651789683331L;

        @Id
        @Column(name="id")
        @XmlID
        private String id;

        @Column(name = "role_name")
        @XmlElement(name = "role_name")
        private String roleName;

        public String getRoleName() {
            return roleName;
        }

        public void setRoleName(String roleName) {
            this.roleName = roleName;
        }

        public String getId() {
            return id;
        }

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

我的配置哪里出错了?我错过了什么?如何修复错误?

4

1 回答 1

0

Kundera cassandra 库在 1.2.4 版本上运行。理想情况下,1.2.8 或更高版本应该始终向后兼容,但不幸的是,在这种情况下它们不是!

于 2013-09-05T15:46:49.833 回答