I just checked out the Spring Greenhouse project as a first step to learn Spring Security.
The project works fine but I was wondering about the following scenarios:
There are two configurations: standard and embedded. The javadoc says the embedded is default. I am not sure how to make it run in standard mode. Has anybody has tried this before?
Secondly in embedded mode I modified the code slightly with the following code to run it with MySql but to my surprise the application is not starting up at all. It throws the following error:
throw new RuntimeException("Unable to determine database version", e);
#Bean(destroyMethod="shutdown")
public DataSource dataSource() {
// EmbeddedDatabaseFactory factory = new EmbeddedDatabaseFactory();
// factory.setDatabaseName("greenhouse");
// factory.setDatabaseType(EmbeddedDatabaseType.);
DriverManagerDataSource mysqldataSource = new DriverManagerDataSource();
mysqldataSource.setDriverClassName("com.mysql.jdbc.Driver");
mysqldataSource.setUrl("jdbc:mysql://localhost/greenhouse?useConfigs=maxPerformance&characterEncoding=utf8");
mysqldataSource.setUsername("root");
mysqldataSource.setPassword("mysql");
return populateDatabase(mysqldataSource);
}
Can anybody please help me on this?
I figured it out by myself.
There was a tag in web.xml and i changed there from embedded to standard.
The problem was in the sql query which was creating the database version table was not mysl complaint. There were other queries also which were not mysql complaint. I changed the sql query and now eveything worked like as expected. The next thing I am gonna do is use some kind og generic database query generator so that i don't have to change the query if in future I change my mind to use post gre sql in place of my sql.
Thank you for all your help and support.
Judging by the exception you're getting, the file you're interested in is GenericDatabaseUpgrader.java
More than half the code there refers to DatabaseVersion which is a table that is created if absent.
Since I doubt you already have it and judging by the exception type (SQLException), I'm inclined to say it's failing to create/insert/retrieve the referenced table.
You can check if you have the table and go from there.
Also, judging by the code you're trying to inject, I'd also look at connection = dataSource.getConnection() as a possible culprit.
P.S. Regarding standard/embedded, it appears you can VM parameters or maven settings to switch between the two. Please check the official forums and specifically this topic for info
Related
There are some samples on http://www.mybatis.org/mybatis-dynamic-sql/docs/select.html.
I want to implement limit/offset for mysql but failed to see any document on describing how to extend this library to support additional where condition.
here is what i'd like to achieve:
SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
.from(animalData)
.where(id, isIn(1, 5, 7))
.and(bodyWeight, isBetween(1.0).and(3.0))
.orderBy(id.descending(), bodyWeight)
.limit(1).offset(10)
.build()
.render(RenderingStrategy.MYBATIS3);
There are a couple of resources you can use.
This page - http://www.mybatis.org/mybatis-dynamic-sql/docs/whereClauses.html - shows an example of using standalone where clauses to build a paging query. This is not exactly what you are looking for, but it shows one way to do it.
There is a unit test showing something that is closer to what you are looking for here - https://github.com/mybatis/mybatis-dynamic-sql/tree/master/src/test/java/examples/paging. This code works for MySQL and you could use it as is.
I hope to make this a little easier in a future release.
I have defined a data table and associated objects in Liferay 6, but when I run the code it says the table doesn't exists, and it's true. The code runs fine when I create the table by hand just copy-pasting the create table from the model implementation, but I expected the table to be created when deploying.
The user has all the privileges needed to create it.
What I'm missing?
I face the same problem. and #urvish is correct you have to change build number in
service properties file.
problem
When multiple developers working on portlet that uses servicebuilder
will give below exception “Build namespace has build number which is
newer than “. When developer commits service.properties file and that
deployed on other developer machine then it will throw below
exception
Best Practice: To avoid these kind of errors, follow these:
create service-ext.properties file at the same locaiton of service.properties
add build.number={higher-value or same value in exception)
Deploy portlet again
.
Check values of build.namespace in service.properties file and value of
select buildNumber from servicecomponent where buildNamespace = <<build.namespace from service.properties>>
Now the buildNumber return from query must be lesser than value of build.number propert in service.properties. If it is not then just set the value of build.number to 9999.
Sometimes due to mismatch, changes are not applied to database.
I'm using Neo4j 2.2.8 and Spring Data in a web application. I'm using xml to configure my database, like:
<neo4j:config storeDirectory="S:\Neo4j\mybase" />
But I'm trying to use a Batch Inserter to add more than 1 million of nodes sourced from a .txt file. After reading the file and setting the List of objects, my code to batch is something like:
public void batchInserter(List<Objects> objects) {
BatchInserter inserter = null;
try {
inserter = BatchInserters.inserter("S:\\Neo4j\\mybase");
Label movimentosLabel = DynamicLabel.label("Movimentos");
inserter.createDeferredSchemaIndex(movimentosLabel).on("documento").create();
for (Objects objs : objects{
Map<String, Object> properties = new HashMap<>();
properties.put("documento", objs.getDocumento());
long movimento = inserter.createNode(properties, movimentosLabel);
DynamicRelationshipType relacionamento = DynamicRelationshipType.withName("CONTA_MOVIMENTO");
inserter.createRelationship(movimento, objs.getConta().getId(), relacionamento, null);
}
} finally {
if (inserter != null) {
inserter.shutdown();
}
}
}
Is it possible to get the path of my database configured in my xml in the "inserter"? Because with the above configuration Neo4j gives me an error about multiple connections. Can I set a property to solve this error of multiple connections? Has anyone had this problem and have any idea how to solve it? Ideas are welcome.
Thanks to everyone!
Your question has several pieces to it:
Error About Multiple Connections
If you're using spring-data with a local database tied to a particular directory or file, be aware that you can't have two neo4j processes opening the same DB at the same time. This means that if you've decided to use BatchInserter against the same file/directory, this cannot happen at all while the JVM that's using the spring-data DB is running. There won't be a way I know of to get around that problem. One option would be to not use the batch inserter against the file, but to use the REST API to do inserting.
get the path of my database configured in my xml
Sure, there's a way to do that, you'd have to consult the relevant documentation. I can't give you the code for that because it depends on which config file your'e talking about and how it's structured, but in essence there should be a way to inject the right thing into your code here, and read the property from the XML file out of that injected object.
But that won't help you given your "Multiple connections" issue mentioned above.
Broadly, I think your solution is either:
Don't run your spring app and your batch inserter at the same time.
Run your spring app, but do insertion via the REST API or other method, so there isn't a multiple connection issue to begin with.
I've a H2 database file which I need to replicate using SymmetricDS.
I can access the database from web console in embedded mode using this url:
jdbc:h2:file:E:/Folder/database;AUTO_SERVER=TRUE;IFEXISTS=TRUE;
But using the same url in node properties file of symmtericds throws following error:
ERROR [server-000] [AbstractSymmetricEngine] [symmetric-engine-startup-0] Could not get a connection to the database: Cannot create PoolableConnectionFactory (IO Exception: "E:/Folder/database outside D:/symmetric-server-3.7.26/tmp/h2" [90028-182]). Waiting for 10 seconds before trying to connect to the database again.
Though if the following url is used in the node properties file of symmetricds, everything works fine but the database is created in symmetric-server-3.7.26/tmp/h2 directory.
jdbc:h2:file:database;AUTO_SERVER=TRUE;
I've not had any luck in solving this issue in past couple of days.
Any kind of help will be greatly appreciated.
Going through H2 documentation I found out that the this behaviour is due to -baseDir option: http://www.h2database.com/html/advanced.html#remote_access .
But how is this option being set automatically and how to disable it..?
Doing some extensive research on the issue, root cause turns out to be the static block of AbstractCommandLauncher class of SymmetricDS:
static {
String symHome = System.getenv("SYM_HOME");
if (symHome == null) {
symHome = ".";
}
System.setProperty("log4j.sym.home", symHome);
if (isBlank(System.getProperty("h2.baseDir"))) {
System.setProperty("h2.baseDir", symHome + "/tmp/h2");
}
DEFAULT_SERVER_PROPERTIES = System.getProperty(SystemConstants.SYSPROP_SERVER_PROPERTIES_PATH, symHome + "/conf/symmetric-server.properties");
log = LoggerFactory.getLogger(AbstractCommandLauncher.class);
initFromServerProperties();
}
And as it turns out, source code of SymmetricDS will have to be modified to resolve it.
This behaviour can not be disabled altogether but overriding it is possible by setting -Dh2.baseDir while running SymmetricDS. The original answer is here
Ok, I am reposting this question because it really drives me crazy.
I have enterprise.wsdl downloaded from salesforce and generated to some jars.
I build path those jars to my Android project in Eclipse.
Here is my code:
ConnectorConfig config = new ConnectorConfig();
config.setAuthEndpoint(authEndPoint);
config.setUsername(userID);
config.setPassword(password + securityToken);
config.setCompression(true);
con = new EnterpriseConnection(config);
con.setSessionHeader(UserPreference.getSessionID(mContext));
String sql = "SELECT something FROM myNameSpace__myCustomObject__c";
con.query(sql);
but it returns me this error:
[InvalidSObjectFault [ApiQueryFault [ApiFault
exceptionCode='INVALID_TYPE' exceptionMessage='sObject type 'abc__c'
is not supported.'] row='-1' column='-1' ]]
I am pretty sure that my userID has been assigned with profile that has read, edit access to that custom object.
My code also can query standard object.
Anyone can advise me what could be wrong?
From what I know there are three reasons it may give this error.
1. User permission which you said is setup correctly.
2. Do you have the custom object deployed to the org where you are trying to establish the connection?
3. Check the enterprise WSDL if it contains the custom object name which you are trying to query.
Hope it helps.