Unable to connect to Cassandra db through Kundera in Play! framework - scala

I am getting the following error when I run my application through SBT Console in Intellij IDEA.
[info] play - Application started (Dev)
[error] c.i.c.c.t.ThriftClientFactory - Error during pool creation: caused by
org.apache.thrift.TException: org.apache.thrift.transport.TTransportException: Read a negative frame size (-2080374784)!
at net.dataforte.cassandra.pool.ConnectionPool.init(ConnectionPool.java:345) ~[cassandra-connection-pool-0.7.1.jar:na]
at net.dataforte.cassandra.pool.ConnectionPool.<init>(ConnectionPool.java:127) ~[cassandra-connection-pool-0.7.1.jar:na]
at com.impetus.client.cassandra.thrift.ThriftClientFactory.createPoolOrConnection(ThriftClientFactory.java:146) ~[kundera-cassandra-2.5.jar:na]
at com.impetus.kundera.loader.GenericClientFactory.load(GenericClientFactory.java:95) [kundera-core-2.5.jar:na]
at com.impetus.kundera.configure.ClientFactoryConfiguraton.configure(ClientFactoryConfiguraton.java:67) [kundera-core-2.5.jar:na]
Caused by: org.apache.thrift.transport.TTransportException: Read a negative frame size (-2080374784)!
at org.apache.thrift.transport.TFastFramedTransport.readFrame(TFastFramedTransport.java:144) ~[libthrift-0.7.0.jar:0.7.0]
at org.apache.thrift.transport.TFastFramedTransport.read(TFastFramedTransport.java:134) ~[libthrift-0.7.0.jar:0.7.0]
at org.apache.thrift.transport.TTransport.readAll(TTransport.java:84) ~[libthrift-0.7.0.jar:0.7.0]
at org.apache.thrift.protocol.TBinaryProtocol.readAll(TBinaryProtocol.java:378) ~[libthrift-0.7.0.jar:0.7.0]
at org.apache.thrift.protocol.TBinaryProtocol.readI32(TBinaryProtocol.java:297) ~[libthrift-0.7.0.jar:0.7.0]
[error] application -
! Internal server error, for (GET) [/] ->
java.lang.ExceptionInInitializerError: null
at models.process.EmployeeProcessImpl$.<init>(EmployeeProcess.scala:82) ~[myEntities.jar:na]
at models.process.EmployeeProcessImpl$.<clinit>(EmployeeProcess.scala) ~[myEntities.jar:na]
at controllers.Application$.<init>(Application.scala:168) ~[na:na]
at controllers.Application$.<clinit>(Application.scala) ~[na:na]
at Routes$$anonfun$routes$1$$anonfun$applyOrElse$1$$anonfun$apply$1.apply(routes_routing.scala:107) ~[na:na]
Caused by: com.impetus.kundera.loader.ClientLoaderException: org.apache.thrift.TException: org.apache.thrift.transport.TTransportException: Read a negative frame size (-2080374784)!
at com.impetus.client.cassandra.thrift.ThriftClientFactory.createPoolOrConnection(ThriftClientFactory.java:151) ~[kundera-cassandra-2.5.jar:na]
at com.impetus.kundera.loader.GenericClientFactory.load(GenericClientFactory.java:95) ~[kundera-core-2.5.jar:na]
at com.impetus.kundera.configure.ClientFactoryConfiguraton.configure(ClientFactoryConfiguraton.java:67) ~[kundera-core-2.5.jar:na]
at com.impetus.kundera.configure.Configurator.configure(Configurator.java:65) ~[kundera-core-2.5.jar:na]
at com.impetus.kundera.KunderaPersistence.initializeKundera(KunderaPersistence.java:109) ~[kundera-core-2.5.jar:na]
Caused by: org.apache.thrift.TException: org.apache.thrift.transport.TTransportException: Read a negative frame size (-2080374784)!
at net.dataforte.cassandra.pool.ConnectionPool.init(ConnectionPool.java:345) ~[cassandra-connection-pool-0.7.1.jar:na]
at net.dataforte.cassandra.pool.ConnectionPool.<init>(ConnectionPool.java:127) ~[cassandra-connection-pool-0.7.1.jar:na]
at com.impetus.client.cassandra.thrift.ThriftClientFactory.createPoolOrConnection(ThriftClientFactory.java:146) ~[kundera-cassandra-2.5.jar:na]
at com.impetus.kundera.loader.GenericClientFactory.load(GenericClientFactory.java:95) ~[kundera-core-2.5.jar:na]
at com.impetus.kundera.configure.ClientFactoryConfiguraton.configure(ClientFactoryConfiguraton.java:67) ~[kundera-core-2.5.jar:na]
Caused by: org.apache.thrift.transport.TTransportException: Read a negative frame size (-2080374784)!
at org.apache.thrift.transport.TFastFramedTransport.readFrame(TFastFramedTransport.java:144) ~[libthrift-0.7.0.jar:0.7.0]
at org.apache.thrift.transport.TFastFramedTransport.read(TFastFramedTransport.java:134) ~[libthrift-0.7.0.jar:0.7.0]
at org.apache.thrift.transport.TTransport.readAll(TTransport.java:84) ~[libthrift-0.7.0.jar:0.7.0]
at org.apache.thrift.protocol.TBinaryProtocol.readAll(TBinaryProtocol.java:378) ~[libthrift-0.7.0.jar:0.7.0]
at org.apache.thrift.protocol.TBinaryProtocol.readI32(TBinaryProtocol.java:297) ~[libthrift-0.7.0.jar:0.7.0]
[error] application - Error while rendering default error page
scala.MatchError: java.lang.ExceptionInInitializerError (of class java.lang.ExceptionInInitializerError)
at play.api.GlobalSettings$class.onError(GlobalSettings.scala:148) ~[play_2.11-2.3.0.jar:2.3.0]
at play.api.DefaultGlobal$.onError(GlobalSettings.scala:206) [play_2.11-2.3.0.jar:2.3.0]
at play.core.server.Server$class.logExceptionAndGetResult$1(Server.scala:76) [play_2.11-2.3.0.jar:2.3.0]
at play.core.server.Server$$anonfun$getHandlerFor$4.apply(Server.scala:86) [play_2.11-2.3.0.jar:2.3.0]
at play.core.server.Server$$anonfun$getHandlerFor$4.apply(Server.scala:84) [play_2.11-2.3.0.jar:2.3.0]
The example I am working with is taken from :
http://blog.knoldus.com/2014/06/22/playing-kundera-cassandra/
I am having Play! 2.4.6 framework with Cassandra 2.2. What could be wrong with the project which is not allowing to connect to the database ? Do I need to make some change regarding CQL or Kundera version so that my database can get connected ? My persistence.xml file is as under:
<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
https://raw.github.com/impetus-opensource/Kundera/Kundera-2.0.4/kundera-core/src/test/resources/META-INF/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="cassandra_employees">
<provider>com.impetus.kundera.KunderaPersistence</provider>
<class>models.domains.Employee</class>
<properties>
<property name="kundera.nodes" value="localhost" />
<property name="kundera.port" value="9042" />
<property name="kundera.keyspace" value="EmployeeExample" />
<property name="kundera.dialect" value="cassandra" />
<property name="kundera.client.lookup.class" value="com.impetus.client.cassandra.thrift.ThriftClientFactory" />
<property name="kundera.cache.provider.class" value="com.impetus.kundera.cache.ehcache.EhCacheProvider" />
<property name="kundera.cache.config.resource" value="/ehcache-test.xml" />
</properties>
</persistence-unit>
</persistence>
Please tell me if I have to make some version related change for Cassandra or CQL and that too in which file ?

used below config and it works fine on my system..
updated cassandra.yaml:
FROM:
start_rpc: false
TO:
start_rpc: true
Persistence.xml:
unit name mentioned below is random which will be used to access this particular persistence.
keyspace name is the name of the table created in cassandra.
<persistence-unit name="persistence">
<provider>com.impetus.kundera.KunderaPersistence</provider>
<properties>
<property name="kundera.nodes" value="localhost" />
<property name="kundera.port" value="9160" />
<property name="kundera.keyspace" value="trial1" />
<property name="kundera.dialect" value="cassandra" />
<property name="kundera.client.lookup.class" value="com.impetus.client.cassandra.thrift.ThriftClientFactory" />
<property name="kundera.pool.size.max.active" value="500" />
<property name="kundera.pool.size.max.total" value="500" />
</properties>

Related

OpenJPA Exception related to JDBC Driver and connection URL in TomEE+

We are facing issue in our application with respect to the persistence configuration. The application runs on TomEE Plus (7.0) and uses Open JPA implementation. Below is the error which we are getting
<openjpa-2.4.2-r422266:1777108 nonfatal general error> org.apache.openjpa.persistence.PersistenceException: There were errors initializing your configuration: <openjpa-2.4.2-r422266:1777108 fatal user error> org.apache.openjpa.util.UserException: A connection could not be obtained for driver class "oracle.jdbc.xa.client.OracleXADataSource" and URL "jdbc:oracle:thin:#//mydburl.abc.com:1881/MYSID.ABC.COM". You may have specified an invalid URL.
We dont' get the above error when using oracle.jdbc.driver.OracleDriver. The XA driver settings were working fine on IBM WebSphere 8.5. Is there anything else which we need to configure in TomEE+ to get it working?
Update
Adding the persistence.xml file as well
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
version="1.0">
<persistence-unit name="MySchema" transaction-type="JTA">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<jta-data-source>myjndi</jta-data-source>
<class>com.abc.jpa.entity.Tuser</class>
<class>com.abc.jpa.entity.Taddress</class>
<properties>
<property name="tomee.jpa.factory.lazy" value="true"></property>
<property name="javax.persistence.jdbc.driver" value="oracle.jdbc.xa.client.OracleXADataSource" />
<property name="javax.persistence.jdbc.url"
value="jdbc:oracle:thin:#//mydburl.abc.com:1881/MYSID.ABC.COM" />
<property name="javax.persistence.jdbc.user" value="userName" />
<property name="javax.persistence.jdbc.password" value="password" />
</properties>
</persistence-unit>
</persistence>
As mentioned, it works fine if I use oracle.jdbc.driver.OracleDriver as the jdbc driver class

Server Tomcat v8.0 Server at localhost failed to start. This is error snapshot

Server Tomcat v8.0 Server at localhost failed to start. This is error snapshot
**I am unable to identify why this problem is occur. when i change something in xml files then this problem start.I send a small snapshot of my problem. Help me to resolve this issue.
After change in this file mentioned below i got error. I send a small snapshot of that file also.Advance thanks.
Project is in maven, spring , mysql**
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/shoot]]
at java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.util.concurrent.FutureTask.get(FutureTask.java:192)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:915)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:871)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1407)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1397)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/shoot]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:153)
... 6 more
Caused by: java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContextException
at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Class.java:2583)
at java.lang.Class.getDeclaredFields(Class.java:1916)
at org.apache.catalina.util.Introspection.getDeclaredFields(Introspection.java:106)
at org.apache.catalina.startup.WebAnnotationSet.loadFieldsAnnotation(WebAnnotationSet.java:256)
at org.apache.catalina.startup.WebAnnotationSet.loadApplicationListenerAnnotations(WebAnnotationSet.java:86)
at org.apache.catalina.startup.WebAnnotationSet.loadApplicationAnnotations(WebAnnotationSet.java:63)
at org.apache.catalina.startup.ContextConfig.applicationAnnotationsConfig(ContextConfig.java:335)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:782)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:306)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:95)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5202)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
... 6 more
Caused by: java.lang.ClassNotFoundException: org.springframework.context.ApplicationContextException
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1332)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1166)
... 20 more
</pre>
File :
<context:component-scan base-package="com.jwt" />
<!-- Getting Database properties -->
<mvc:annotation-driven />
<mvc:resources mapping="/resources/**" location="/resources/" />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/pages/" />
<property name="suffix" value=".jsp" />
</bean>
<!-- DataSource -->
<bean class="org.springframework.jdbc.datasource.DriverManagerDataSource"
id="dataSource">
</bean>
<!-- Hibernate SessionFactory -->
<bean id="sessionFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="packagesToScan" value="com.jwt"></property>
</bean>
<!-- Transaction -->
<bean id="transactionManager"
class="org.springframework.orm.jpa.JpaTransactionManager
">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
Probably, spring-context.jar is not inclded in your application. If you are using maven, please check dependency for spring-context jar file:
<dependency>
<groupid>org.springframework</groupid>
<artifactid>spring-context</artifactid>
<version>${org.springframework.version}</version>
</dependency>

JPA persistence provider

I have a problem with my jpa project.
Already found this thread:
JPA: configure persistence provider
My persistence.xml is at:
C:\workspace\DevWorkSample\src\META-INF
so this seems to be correct.
My persistence.xml looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="CustomerQuery">
<jta-data-source>java:comp/env/jdbc/MyDataSource</jta-data-source>
<class>myjpa.CustomerAcct</class>
<!-- exclude-unlisted-classes>true</exclude-unlisted-classes -->
<properties>
<property name="openjpa.LockTimeout" value="30000" />
<property name="openjpa.jdbc.TransactionIsolation" value="read-committed" />
<property name="openjpa.Log" value="none" />
<property name="openjpa.jdbc.UpdateManager" value="operation-order" />
<property name="openjpa.ConnectionURL" value="DB URL"/>
<property name="openjpa.ConnectionDriverName" value="Driver Name"/>
<property name="openjpa.ConnectionUserName" value="userid"/>
<property name="openjpa.ConnectionPassword" value="password"/>
<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
</properties>
</persistence-unit>
</persistence>
Errors:
1.
An error occurred in the com.ibm.websphere.persistence.PersistenceProviderImpl persistence provider when it attempted to create the container entity manager factory for the CustomerQuery persistence unit. The following error occurred: There was an error when invoking the static newInstance method on the named factory class "com.ibm.ws.persistence.jdbc.kernel.WsJpaJDBCBrokerFactory". See the nested exception for details.
2.
For the [com.ibm.devworks.Deposit] servlet, com.ibm.devworks.Deposit servlet class was found, but a resource injection failure has occurred. CWNEN0030E: The server was unable to obtain an object instance for the java:comp/env/com.ibm.devworks.Deposit/emf reference. The exception message was: <openjpa-2.2.3-SNAPSHOT-r422266:1642995 fatal general error> org.apache.openjpa.persistence.PersistenceException: There was an error when invoking the static newInstance method on the named factory class "com.ibm.ws.persistence.jdbc.kernel.WsJpaJDBCBrokerFactory". See the nested exception for details.
What do I have to change to fix this?

Hibernate mongodb configuration file

<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="hibernate.ogm.datastore.provider">mongodb</property>
<property name="hibernate.ogm.datastore.host">127.0.0.1</property>
<property name="hibernate.ogm.datastore.port">27017</property>
<property name="hibernate.ogm.datastore.database">eatery</property>
<property name="hibernate.ogm.datastore.create_database">true</property>
<mapping class="com.ws.web.models.Reservation" />
</session-factory>
</hibernate-configuration>
Does anyone know hoe to configure hibernate for mongodb. Docs says that there is no need of dialect. but i got errors
Exception in thread "main" org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.determineDialect(DialectFactoryImpl.java:104)
at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:71)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:209)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1887)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1845)
at com.ws.web.models.Test.main(Test.java:17)
First of all i think your configuration is wrong. The proporties that you used should be placed in persistence.xml file. The example is here.
The necessary properties with description are here

Access to Derby database from another project using EclipseLink

I have a dynamic web project that creates and writes Derby database. Everything works fine. Here is the persistence.xml I used:
<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" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="alerts" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>test.Alert</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver" />
<property name="javax.persistence.jdbc.url" value="jdbc:derby:databases/bDb;create=true" />
<property name="javax.persistence.jdbc.user" value="user" />
<property name="javax.persistence.jdbc.password" value="user-pwd" />
<!-- EclipseLink should create the database schema automatically -->
<property name="eclipselink.ddl-generation" value="create-tables" />
<property name="eclipselink.ddl-generation.output-mode"
value="database" />
<property name="eclipselink.logging.level" value="FINEST" />
<property name="eclipselink.logging.level.sql" value="FINEST" />
</properties>
</persistence-unit>
Now I would like to create a java project that reads the same database. So I use the same persistence.xml (except that I change "create=true" to "create=false" since I don't want to create a new table). but I got this error:
[EL Severe]: ejb: 2014-12-28 22:27:20.379--ServerSession(1488953836)--Thread(Thread[DefaultQuartzScheduler_Worker-7,5,main])--Local Exception Stack:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Database 'databases/bDb' not found.
Error Code: 40000
at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:331)
at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:326)
at org.eclipse.persistence.sessions.DefaultConnector.connect(DefaultConnector.java:138)
at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:162)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.setOrDetectDatasource(DatabaseSessionImpl.java:204)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:741)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:239)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:685)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getAbstractSession(EntityManagerFactoryDelegate.java:204)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:304)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:336)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:302)
If I use "create=true", it will create a new database instance (it is different from the one I created from the web project). How do I fix this problem? Thanks a lot!
Since you're using a relative filename in your jdbc.url (databases/bDb), Derby is looking for the database relative to your application start directory.
And your two separate applications have two separate directories in which they are being run.
You could address this in a number of ways:
Arrange for each application to be run from the same directory
Use an absolute database path name, not a relative one, in your jdb.url value
Use the Derby Network Server configuration, not the Derby Embedded configuration
And there are undoubtedly other approaches.