Does dynamic providing of host details is allowed in kundera ?
Hi Team,
We are using weblogic server and we don't want to provide Host details and cassandra user authentication credentials in persistence.xml file. We want to provide these details at run time.
Issue here is : When weblogic server deploying the war, weblogic server finds persistence.xml and it is trying to establish the connection with cassandra, and it is not able to find host details and deployment is getting cancelled. So is there a way where we can create entity manager without persistence.xml or is there a way where we can specify datasource verificaiton to false in weblogic? Or is there a way where kundera will simply return true flag while establishing connection, so that weblogic will proceed further?
Hi @idofmrsandeep,
you can define persistence unit without database specific properties.
<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="kundera_pu">
<provider>com.impetus.kundera.KunderaPersistence</provider>
<properties>
<property name="kundera.dialect" value="cassandra"/>
<property name="kundera.ddl.auto.prepare" value="create" />
<property name="kundera.client.lookup.class" value="com.impetus.client.cassandra.thrift.ThriftClientFactory" />
</properties>
</persistence-unit>
</persistence>
You can pass node, port, database, username, password, etc. using Map of properties
propertiesMap.put("kundera.nodes", host);
propertiesMap.put("kundera.port", port);
propertiesMap.put("kundera.keyspace", dbName);
propertiesMap.put("kundera.username", username);
propertiesMap.put("kundera.password", pswd);
emf = Persistence.createEntityManagerFactory(EthConstants.PU, propertiesMap);
Hi devender-yadav ,
Thank you for response. We did same but we are facing problem with application deployment. while deploying weblogic server is trying to connect to DB and as host details are not there, it is throwing Error and deployment is failing.
@idofmrsandeep connection details are needed while creating entitymangerfactory. You need to provide it via properties map as I mentioned above.
Can you please share error logs.
Hi devender-yadav ,
I am providing those details while creation of EMF. But before this code is invoking, weblogic itself trying to connect to DHCS, after seeing persistence.xml. I am not initiating the connection.
Weblogic server while deploying war file, it is trying to create connection and test the connection on its own.
@idofmrsandeep,
Please send sample project; we can try to replicate this at our end.
Thank you Yadav,
I will try to create a sample project and send to you.
Yadav can you please let me know few details. like
- Can we create application by completely removing persistence.xml ? If so can you please share sample code?
- Is there a Datasource creation for Kundera in weblogic server ? Or we need to depend only on JPA mopdel?
- Is data as Object is full length developed and can we use it for production purpose? If it is the option to avoid persistence.xml?
Can we create application by completely removing persistence.xml
No.
Is there a Datasource creation for Kundera in weblogic server ? Or we need to depend only on JPA model?
If you create Datasource through weblogic (by default with persistence.xml), you cannot provide properties at runtime. Can you share your sample application?
Is data as Object is full length developed and can we use it for production purpose? If it is the option to avoid persistence.xml?
This module is just a wrapper over Kundera's other module. Checkout its limitation. Since this is a experimental feature, I dont recommend it for production as of now.
Data-as-object module also uses persistence.xml although it's not exposed to users.
Hi Yadav,
Thank you. I am trying to create sample project to send. Meanwhile I will provide you the error that is thrown by weblogic server. can you please see if you can give some pointers after seeing this. <May 17, 2018 12:19:44 PM IST> <Error> <Deployer> <BEA-149265> <Failure occurred in the execution of deployment request with ID "5567322958431" for task "1" on [partition-name: DOMAIN]. Error is: "weblogic.application.ModuleException: weblogic.application.naming.EnvironmentException: Error processing persistence unit cassandra_pu of module dhcsDS: Error instantiating the Persistence Provider class com.impetus.kundera.KunderaPersistence of the PersistenceUnit cassandra_pu: java.lang.ClassNotFoundException: com.impetus.kundera.KunderaPersistence" weblogic.application.ModuleException: weblogic.application.naming.EnvironmentException: Error processing persistence unit cassandra_pu of module dhcsDS: Error instantiating the Persistence Provider class com.impetus.kundera.KunderaPersistence of the PersistenceUnit cassandra_pu: java.lang.ClassNotFoundException: com.impetus.kundera.KunderaPersistence at weblogic.application.internal.ExtensibleModuleWrapper.prepare(ExtensibleModuleWrapper.java:114) at weblogic.application.internal.flow.ModuleListenerInvoker.prepare(ModuleListenerInvoker.java:100) at weblogic.application.internal.flow.ModuleStateDriver$1.next(ModuleStateDriver.java:196) at weblogic.application.internal.flow.ModuleStateDriver$1.next(ModuleStateDriver.java:191) at weblogic.application.utils.StateMachineDriver$ParallelChange.run(StateMachineDriver.java:83) Truncated. see log file for complete stacktrace Caused By: weblogic.application.naming.EnvironmentException: Error processing persistence unit cassandra_pu of module dhcsDS: Error instantiating the Persistence Provider class com.impetus.kundera.KunderaPersistence of the PersistenceUnit cassandra_pu: java.lang.ClassNotFoundException: com.impetus.kundera.KunderaPersistence at weblogic.persistence.BasePersistenceUnitInfo.getPersistenceProvider(BasePersistenceUnitInfo.java:601) at weblogic.persistence.BasePersistenceUnitInfo.initializeEntityManagerFactory(BasePersistenceUnitInfo.java:610) at weblogic.persistence.BasePersistenceUnitInfo.init(BasePersistenceUnitInfo.java:199) at weblogic.persistence.BaseJPAIntegrationProvider.createPersistenceUnitInfo(BaseJPAIntegrationProvider.java:54) at weblogic.persistence.AbstractPersistenceUnitRegistry.storeDescriptors(AbstractPersistenceUnitRegistry.java:422) Truncated. see log file for complete stacktrace
Hi Yadav,
I uploaded sample project. Please try to deploy this in weblogic server. Libraries screen shot I have given. Error trace is posted in previous post. I am using Weblogic server version 12.2.1.0.0, Java version 8, Kundera Version Kundera-Cassandra-3.12.jar Please let me know if you need any further details from me.
java.lang.ClassNotFoundException: com.impetus.kundera.KunderaPersistence
@idofmrsandeep seems like Kundera-core is missing from the classpath.
Hi Yadav,
Both Kundera-core-3.12.jar and kundera-cassandra-3.12.jar are available , Are you referening to any other jar. if so can you please let me know full jar name. I will download that jar. Actually I loaded complete set of jars.
Hi Yadav, If I have attached 2 screenshots, where in first screenshot you can see that kundera-core-3.12.jar is available.
Hi Yadav,
I fixed this class not found exception. Now I am getting this error. "Cannot build a cluster without contact points". I copied my persistence.xml file here. I am using Cassandra Datastax class instead of Thrift class. Also this error is gone when we place server ip address, port and credentials in xml file. ( :( Ideally I dont want to provide these details in xml file).
<persistence-unit name="kundera_pu">
<provider>com.impetus.kundera.KunderaPersistence</provider>
<properties>
<property name="kundera.dialect" value="cassandra"/>
<property name="kundera.client.lookup.class"
value="com.impetus.kundera.client.cassandra.dsdriver.DSClientFactory" />
</properties>
</persistence-unit>
Error:
<Error> <Deployer> <BEA-149265> <Failure occurred in the execution of deployment request with ID "606852003208619" for task "2" on [partition-name: DOMAIN]. Error is: "weblogic.application.ModuleException: java.lang.IllegalArgumentException: Cannot build a cluster without contact points"
weblogic.application.ModuleException: java.lang.IllegalArgumentException: Cannot build a cluster without contact points
at weblogic.application.internal.ExtensibleModuleWrapper.prepare(ExtensibleModuleWrapper.java:114)
at weblogic.application.internal.flow.ModuleListenerInvoker.prepare(ModuleListenerInvoker.java:100)
at weblogic.application.internal.flow.ModuleStateDriver$1.next(ModuleStateDriver.java:196)
at weblogic.application.internal.flow.ModuleStateDriver$1.next(ModuleStateDriver.java:191)
at weblogic.application.utils.StateMachineDriver$ParallelChange.run(StateMachineDriver.java:83)
Truncated. see log file for complete stacktrace
Caused By: java.lang.IllegalArgumentException: Cannot build a cluster without contact points
at com.datastax.driver.core.Cluster.checkNotEmpty(Cluster.java:119)
at com.datastax.driver.core.Cluster.<init>(Cluster.java:112)
at com.datastax.driver.core.Cluster.buildFrom(Cluster.java:178)
at com.datastax.driver.core.Cluster$Builder.build(Cluster.java:1335)
at com.impetus.kundera.client.cassandra.dsdriver.DSClientFactory.createPoolOrConnection(DSClientFactory.java:265)
Truncated. see log file for complete stacktrace
>
@idofmrsandeep it should work in both ways. Can you share the truncated logs from your log file?