I am using Java 1.7 with neo4j-community-2.0-1.1 to build a sample neo4j graph database. Please see below my code
import org.neo4j.graphdb.Direction;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.RelationshipType;
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.factory.GraphDatabaseFactory;
public class showData {
private static final String Neo4J_DBPath = "/Technology/neo4j-community-2.0-1.1";
/**
* #param args
*/
Node first;
Node second;
Relationship relation;
GraphDatabaseService graphDataService;
//List of relationships
private static enum RelationshipTypes implements RelationshipType
{
KNOWS
}
public static void main(String[] args)
{
showData data = new showData();
data.createDatabase();
data.removeData();
data.shutDown();
}
void createDatabase()
{
//GraphDatabaseService
graphDataService = new GraphDatabaseFactory().newEmbeddedDatabase(Neo4J_DBPath);
// Begin transaction
Transaction transaction = graphDataService.beginTx();
try
{
// create nodes and set the properties the nodes
first = graphDataService.createNode();
first.setProperty("Name", "Ravneet Kaur");
second = graphDataService.createNode();
second.setProperty("Name", "Harpreet Singh");
//specify the relationships
relation = first.createRelationshipTo(second, RelationshipTypes.KNOWS);
relation.setProperty("relationship-type", "knows");
//success transaction
System.out.println(first.getProperty("name").toString());
System.out.println(relation.getProperty("relationship-type").toString());
System.out.println(second.getProperty("name").toString());
transaction.success();
}
finally
{
transaction.finish();
}
}
void removeData()
{
Transaction transaction = graphDataService.beginTx();
try
{
first.getSingleRelationship(RelationshipTypes.KNOWS,Direction.OUTGOING).delete();
System.out.println("Nodes are deleted");
//delete the nodes
first.delete();
second.delete();
transaction.success();
}
finally
{
transaction.finish();
}
}
void shutDown()
{
graphDataService.shutdown();
System.out.println("Database is shutdown");
}
}
Earlier I was using Jave 1.6 to compile this code, but got to know that this neo4j jar complies with jdk 1.7. So I changed it to JDK 1.7 and made all necessary changes in Installed JRE, Execution Environments and Java Build Path in eclipse to point to latest java.
Now I get the following error
Exception in thread "main" java.lang.RuntimeException: Error starting org.neo4j.kernel.EmbeddedGraphDatabase, /Technology/neo4j-community-2.0-1.1
at org.neo4j.kernel.InternalAbstractGraphDatabase.run(InternalAbstractGraphDatabase.java:330)
at org.neo4j.kernel.EmbeddedGraphDatabase.<init>(EmbeddedGraphDatabase.java:63)
at org.neo4j.graphdb.factory.GraphDatabaseFactory$1.newDatabase(GraphDatabaseFactory.java:92)
at org.neo4j.graphdb.factory.GraphDatabaseBuilder.newGraphDatabase(GraphDatabaseBuilder.java:198)
at org.neo4j.graphdb.factory.GraphDatabaseFactory.newEmbeddedDatabase(GraphDatabaseFactory.java:69)
at com.PNL.data.neo4j.showData.createDatabase(showData.java:45)
at com.PNL.data.neo4j.showData.main(showData.java:34)
Caused by: org.neo4j.kernel.lifecycle.LifecycleException: Component 'org.neo4j.kernel.impl.transaction.XaDataSourceManager#7594035c' was successfully initialized, but failed to start. Please see attached cause exception.
at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:509)
at org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:115)
at org.neo4j.kernel.InternalAbstractGraphDatabase.run(InternalAbstractGraphDatabase.java:307)
... 6 more
Caused by: org.neo4j.kernel.lifecycle.LifecycleException: Component 'org.neo4j.kernel.impl.nioneo.xa.NeoStoreXaDataSource#24367e26' was successfully initialized, but failed to start. Please see attached cause exception.
at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:509)
at org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:115)
at org.neo4j.kernel.impl.transaction.XaDataSourceManager.start(XaDataSourceManager.java:164)
at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:503)
... 8 more
Caused by: org.neo4j.kernel.impl.storemigration.UpgradeNotAllowedByConfigurationException: Failed to start Neo4j with an older data store version. To enable automatic upgrade, please set configuration parameter "allow_store_upgrade=true"
at org.neo4j.kernel.impl.storemigration.ConfigMapUpgradeConfiguration.checkConfigurationAllowsAutomaticUpgrade(ConfigMapUpgradeConfiguration.java:39)
at org.neo4j.kernel.impl.storemigration.StoreUpgrader.attemptUpgrade(StoreUpgrader.java:71)
at org.neo4j.kernel.impl.nioneo.store.StoreFactory.tryToUpgradeStores(StoreFactory.java:144)
at org.neo4j.kernel.impl.nioneo.store.StoreFactory.newNeoStore(StoreFactory.java:124)
at org.neo4j.kernel.impl.nioneo.xa.NeoStoreXaDataSource.start(NeoStoreXaDataSource.java:323)
at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:503)
... 11 more
BTW: Also my neo4j configuration parameter "allow_store_upgrade" is set to "true".
Any help will be really appreciated.
Regards
In your code the configuration is not picked up. To change this use the following snippet to initialize your db:
GraphDatabaseService graphDb = new GraphDatabaseFactory()
.newEmbeddedDatabaseBuilder(Neo4J_DBPath)
.loadPropertiesFromFile("confdir/neo4j.properties")
.newGraphDatabase();
Make sure neo4j.properties contains allow_store_upgrade=true. Alternatively you can use the deprecated setConfig(name, value) on the factory.
Related
When the rtu.smallview.xhtml action event is triggered it requests info from the java bean, from the database select and hands it back to the xhtml.
The xhtml was not displaying the data from the database, so I added breakpoints in the java bean to figure out what was going wrong, but when the program loaded it never hit the breakpoint in the bean.
The server output is saying this when the program is loaded:
Info: WELD-000119: Not generating any bean definitions from Beans.RTU.RTU_SmallView_Bean because of underlying class loading error: Type pojo.rtu.RTU_unit not found. If this is unexpected, enable DEBUG logging to see the full error.
So I stopped the server, clean and built the project again, and when it runs for the first time it loads the bean, the information is retrieved and displayed. Though if I clean and build the project again, when it runs the second time it displays the same WELD-000119 error.
I copy and pasted just the code to make the RTU section run to a new project and the server doesn't ever throw this error, and it works every time the bean is requested and every time the server is started.
Edit 1:
When I restart NetBeans and Clean and Build the project after it starts it says this:
Note: C:\Users\Administrator\Documents\NetBeansProjects\OIUSA_1\src\java\Beans\RTU\RTU_SmallView_Bean.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
This is the only java class it says this about, so here is the code I used for that class:
package Beans.RTU;
import Database.RTU.RTU_SmallView_Select;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Named;
import javax.enterprise.context.RequestScoped;
import pojo.rtu.RTU_unit;
/**
*
* #author Administrator
*/
#Named(value = "rtu_SmallView_Bean")
#RequestScoped
public class RTU_SmallView_Bean {
public RTU_SmallView_Bean() {
try {
RTU_SmallView_Select selectData;
selectData = new RTU_SmallView_Select();
this.smallViewList = selectData.getData();
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
}
List<RTU_unit> smallViewList = new ArrayList();
String unit_type;
int unit_number;
String rig_name;
String location_name;
public List<RTU_unit> getSmallViewList() {
return smallViewList;
}
public void setSmallViewList(List<RTU_unit> smallViewList) {
this.smallViewList = smallViewList;
}
public String getUnit_type() {
return unit_type;
}
public void setUnit_type(String unit_type) {
this.unit_type = unit_type;
}
public int getUnit_number() {
return unit_number;
}
public void setUnit_number(int unit_number) {
this.unit_number = unit_number;
}
public String getRig_name() {
return rig_name;
}
public void setRig_name(String rig_name) {
this.rig_name = rig_name;
}
public String getLocation_name() {
return location_name;
}
public void setLocation_name(String location_name) {
this.location_name = location_name;
}
}
My project structure is as follows:
Sources:
Beans.RTU.RTU_SmallView_Bean.java
Database.RTU.RTU_SmallView_Select.java
pojo.rtu.RTU_unit.java
Webpages:
rtu.rtu_smallview.xhtml
I am thinking it has something to do with the actual server, but I'm not sure where to start looking for this error. If you would like to see the actual code for the beans and what not, let me know and I'll edit the question with all the code. Thanks
Problem has been solved, the file RTU_Unit.java was in a folder called pojo.rtu. I deleted the folder, made it again with a new name pojo.rtus, refactored the file RTU_Unit.java for the new folder and the problem has gone away.
I've abandoned GlassFish 4-point-anything in favor of Payara41. Amazingly GF has unresolved JDBC and JMS Resources configuration bugs. See:
Glassfish Admin Console throws java.lang.IllegalStateException when creating JDBC Pool
Payara perfectly fixed the JMS configuration issues. So all I need are the environment properties my standalone Java Client needs to get an InitialContext(env) to lookup() those Resources.
Note: InitalContext() doesn't work in a standalone. Only in an EJB Container that can look up the {Payara Home}/glassfish/lib/jndi-properties file. That file has one property so that's what I have in my code below:
Key: "java.naming.factory.initial"
Value: "com.sun.enterprise.naming.impl.SerialInitContextFactory"
That set off a series of NoClassDerfinitionFound Exceptions that led me to add these jars with these classes to my client's buildpath, and to /glassfish/lib/. They are in the order I encountered them.
"glassfish-naming.jar" w/ "com.sun.enterprise.naming.impl.SerialInitContextFactory"
"internal-api-3.1.2.jar" w/ "org.glassfish.internal.api.Globals"
" hk2-api-2.1.46.jar " w/ "org.glassfish.hk2.api.ServiceLocator"
"appserv-rt.jar" from glassfish/lib added to client build path
But now my code throws a java.lang.NoSuchMethodError for Globals.getDefaultHabitat(). Please note, below the Exception doesn't get caught in my catch block. (And I don't see it in Payara's service.log either.)
I know my client finds Globals.class, because adding it caused the NoClassDefinitionFound for ServiceLocator. Are there two "Globals.class" out there ... one w/ and one w/o that method. Or is the "Lorg" in console output really different from "org", i.e. is there a "Lorg/glassfish/hk2/api/ServiceLocator"?
I'm stuck. And this seems such a bread and butter kind of need -- environment properties a standalone Java client needs to get Payara's InitialContext -- it would be nice to be able to add it here for everyone to use (in addition to the jars I've already located.) I'd love to see Payara soar, because I love its Admin Console compared to JBoss and MayFly's XML orientation. Any suggestions? I'm stumped.Code and console output follows:
Code
package org.america3.testclasses;
import java.util.Properties;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.naming.Context;
import javax.naming.InitialContext;
import org.america3.toolkit.U;
public class Test2 implements MessageListener {
static final Properties JNDI_PROPERTIES = new Properties() {
private static final long serialVersionUID = 1L;
{/*This property key:vlaue pair is specified in Payara41/glassfish/lib/jndi-properties*/
/*The class it calls for is in Payara41/glassfish/lib/glassfish-naming.jar*/
this.put ("java.naming.factory.initial","com.sun.enterprise.naming.impl.SerialInitContextFactory");}
};
//constructor
public Test2 () {
String iAmM = U.getIAmMShort(Thread.currentThread().getStackTrace());
System.out.println(iAmM + "beg");
try {
Context jndiContext = (Context) new InitialContext(JNDI_PROPERTIES);
} catch (Exception e) {
System.out.println(" " + iAmM + "InitialContext failed to instantiate");
System.out.println(" " + iAmM + "Exception : " + e.getClass().getName());
System.out.println(" " + iAmM + "e.getMessage(): " + e.getMessage());
System.out.println(" " + iAmM + "e.getMessage(): " + e.getCause());
e.printStackTrace();
}
System.out.println(iAmM + "end");
}
public static void main(String[] args) {
Test2 messageCenter = new Test2 ();
}
public void onMessage(Message arg0) {
// TODO Auto-generated method stub
}
}
Console
Test2.<init> () beg
Exception in thread "main" java.lang.NoSuchMethodError: org.glassfish.internal.api.Globals.getDefaultHabitat()Lorg/glassfish/hk2/api/ServiceLocator;
at com.sun.enterprise.naming.impl.SerialInitContextFactory.<init>(SerialInitContextFactory.java:126)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.init(Unknown Source)
at javax.naming.InitialContext.<init>(Unknown Source)
at org.america3.testclasses.Test2.<init>(Test2.java:24)
at org.america3.testclasses.Test2.main(Test2.java:36)
PS: Could someone with enough points add a "Paraya" tag below. I mean with Glassfish's console throwing exceptions when used to configure any JNDI or JMS Resource I think many people will switch.
JAR internal-api-3.1.2.jar is for Glassfish v3, and its Globals class has a method getDefaultHabitat() that returns Habitat:
public static Habitat getDefaultHabitat() {
return defaultHabitat;
}
However, Glassfish v4 has changed method signatures, and you have to use new Glassfish v4 internal API whose Globals class has appropriate method getDefaultHabitat() that returns ServiceLocator:
public static ServiceLocator getDefaultHabitat() {
return defaultHabitat;
}
In other words, replace internal-api-3.1.2.jar with internal-api-4.1.jar which can be found on Maven Central here
You should add ${PAYARA-HOME}/glassfish/lib/gf-client.jar to your classpath as this references all the other required jars in it's META-INF/MANIFEST.MF. Please note, it uses relative path references so you really need to install Payara on the client machine.
My Main
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class MainApp {
public static void main(String[] args) {
System.out.println("hola");
ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml");
HelloWorld obj = (HelloWorld) context.getBean("helloWorld");
obj.getMessage();
}
}
Exception in thread "main" java.lang.ExceptionInInitializerError
at org.springframework.context.support.AbstractRefreshableApplicationContext.createBeanFactory(AbstractRefreshableApplicationContext.java:201)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:127)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:551)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:465)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.tutorialspoint.MainApp.main(MainApp.java:9)
Caused by: java.lang.NullPointerException
at org.springframework.beans.factory.support.
DefaultListableBeanFactory.<clinit>(DefaultListableBeanFactory.java:108)
... 7 more
The NullPointerException error is at almost impossible location:
static {
ClassLoader cl = DefaultListableBeanFactory.class.getClassLoader();
try {
javaxInjectProviderClass = cl.loadClass("javax.inject.Provider"); /* line 108 */
} catch (ClassNotFoundException ex) {
// JSR-330 API not available - Provider interface simply not supported then.
}
}
This means that the class is not able to get its own classloader. You must have done something really bad to get this error. Check your JRE/JDK, IDE, ...
UPDATE
There is no explanation other than that you are probably trying to put Spring JARs into JRE's library folder (${java.home}/jre/lib). If that is the case, that is simply wrong. If you really want to include external JARs within JRE, then put them in the official extension directory - ${java.home}/jre/lib/ext.
I needed to write a JavaAgent in a Lotus Notes 6.5 DB to access a web service. I used Axis Apache API for this purpose. I created A Java agent and added the jar files of axis in the agent by using Edit Project button.
Below is the agent code:
import lotus.domino.*;
import javax.xml.*;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import javax.xml.namespace.QName;
import java.net.URL;
public class JavaAgent extends AgentBase {
public void NotesMain() {
try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
String endpoint = "http://ws.apache.org:5049/axis/services/echo";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(endpoint) );
call.setOperationName(new QName("http://soapinterop.org/", "echoString"));
String ret = (String) call.invoke( new Object[] { "Hello!" } );
System.out.println("Sent 'Hello!', got '" + ret + "'");
} catch(Exception e) {
e.printStackTrace();
}
}
}
And below is the exception thrown:
java.lang.ExceptionInInitializerError: org.apache.commons.discovery.DiscoveryException: No implementation defined for org.apache.commons.logging.LogFactory
at org.apache.commons.discovery.tools.SPInterface.newInstance(SPInterface.java:197)
at org.apache.commons.discovery.tools.DiscoverClass.newInstance(DiscoverClass.java:579)
at org.apache.commons.discovery.tools.DiscoverSingleton.find(DiscoverSingleton.java:418)
at org.apache.commons.discovery.tools.DiscoverSingleton.find(DiscoverSingleton.java:378)
at org.apache.axis.components.logger.LogFactory$1.run(LogFactory.java:84)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.axis.components.logger.LogFactory.getLogFactory(LogFactory.java:80)
at org.apache.axis.components.logger.LogFactory.<clinit>(LogFactory.java:72)
at org.apache.axis.configuration.EngineConfigurationFactoryFinder.<clinit>(EngineConfigurationFactoryFinder.java:94)
at org.apache.axis.client.Service.<init>(Service.java:111)
at JavaAgent.NotesMain(JavaAgent.java:17)
at lotus.domino.AgentBase.runNotes(Unknown Source)
at lotus.domino.NotesThread.run(NotesThread.java:218)
I thried to follow some links on the internet like, But i was not able to get exactly what it was asking to do. eg: http://www-10.lotus.com/ldd/nd6forum.nsf/55c38d716d632d9b8525689b005ba1c0/40d033fba3897f4d85256cd30034026a?OpenDocument
Any help will be great. All i wanted to do is write an agent so that i can access a web service, say temperature conversion web service on w3schools. http://www.w3schools.com/webservices/tempconvert.asmx?op=FahrenheitToCelsius
I googled with your error message and this is the first hit:
http://croarkin.blogspot.fi/2010/08/commons-logging-headaches-with-axis.html
It suggests using a commons-logging.properties file with:
org.apache.commons.logging.Log = org.apache.commons.logging.impl.Log4JLogger
org.apache.commons.logging.LogFactory = org.apache.commons.logging.impl.LogFactoryImpl
or putting this to your code:
#BeforeClass
public static void beforeClass() {
System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.Log4JLogger");
System.setProperty("org.apache.commons.logging.LogFactory", "org.apache.commons.logging.impl.LogFactoryImpl");
}
Probably you've already tried this because it's the first hit with google but just in case...
I am using Berkely DB and I have an error which says that mutations are missing. What does this mean?
Exception: com.sleepycat.persist.evolve.IncompatibleClassException: Mutation is missing to evolve class: TopMoveDAO.TopMoveClass version: 0 Error: java.lang.ClassNotFoundException: TopMoveDAO.TopMoveClasscom.sleepycat.persist.evolve.IncompatibleClassException: Mutation is missing to evolve class: TopMoveDAO.TopMoveClass version: 0 Error: java.lang.ClassNotFoundException: TopMoveDAO.TopMoveClass
at com.sleepycat.persist.impl.PersistCatalog.(PersistCatalog.java:365)
at com.sleepycat.persist.impl.Store.(Store.java:180)
at com.sleepycat.persist.EntityStore.(EntityStore.java:165)
at TopMoveDAO.TopMovePut.setup(TopMovePut.java:40)
at TopMoveDAO.TopMovePut.run(TopMovePut.java:59)
at TopMoveDAO.TopMovePut.main(TopMovePut.java:84)
package TopMoveDAO;
import java.io.File;
import java.util.Timer;
import java.util.TimerTask;
import com.sleepycat.je.DatabaseException;
import com.sleepycat.je.Environment;
import com.sleepycat.je.EnvironmentConfig;
import com.sleepycat.persist.EntityStore;
import com.sleepycat.persist.StoreConfig;
public class TopMovePut {
//private static File envHome = new File("C:/dev/je-3.3.75/");
private static File envHome = new File("C:/dev/db/berkeley");
private Environment envmnt;
private EntityStore store;
private TopMoveDA sda;
//Next we create a method that simply opens our database environment and entity store for us.
// The setup() method opens the environment and store
// for us.
public void setup()
throws DatabaseException {
EnvironmentConfig envConfig = new EnvironmentConfig();
StoreConfig storeConfig = new StoreConfig();
envConfig.setAllowCreate(true);
storeConfig.setAllowCreate(true);
// Open the environment and entity store
envmnt = new Environment(envHome, envConfig);
store = new EntityStore(envmnt, "EntityStore", storeConfig);
}
//We also need a method to close our environment and store.
// Close our environment and store.
public void shutdown()
throws DatabaseException {
store.close();
envmnt.close();
}
//Populate the entity store
private void run()
throws DatabaseException {
setup();
// Open the data accessor. This is used to store
// persistent objects.
sda = new TopMoveDA(store);
// Instantiate and store some entity classes
PriceElement pe1 = new PriceElement();
pe1.setSecCode("UNO");
pe1.setLastPrice(1);
sda.pIdx.put(pe1);
shutdown();
}
//main
public static void main(String args[]) {
//SimpleStorePut ssp = new SimpleStorePut();
TopMovePut tmp = new TopMovePut();
try {
//ssp.run();
tmp.run();
} catch (DatabaseException dbe) {
System.err.println("TopMovePut: " + dbe.toString());
dbe.printStackTrace();
} catch (Exception e) {
System.out.println("Exception: " + e.toString());
e.printStackTrace();
}
System.out.println("All done - TopMovePut.");
}
}
You have to write a mutation to evolve your database. Deleting the database will not solve the problem, only circumvent it ( which is fine if you have not yet deployed to production, but if you do not want to lose your existing data then write a mutation.)
Some changes to your persistent entities are handled automatically by Berkley db, such as adding a field. Ones that involve deleting data or renaming fields generally require you to write an explicit mutation. When you start using mutations you will also have to annotate your entities with version numbers which the mutations will refer to - even if the mutation is handled automatically you will have to increment the version number. When you make major structural changes such as using a different primary key, you will have to do an entire store conversion.
Take care when evolving a database in a replicated environment. I would strongly suggest reading the following:
Package com.sleepycat.persist.evolve (Oracle - Berkeley DB Java Edition API)
You have to delete your existing database each time.