I am trying to create an event formatter for MySql in WSO2 but am hitting a problem. It appears to be linked to the use of "Composite Key Columns". The error I am getting is:
ERROR - {MysqlEventAdaptorType}
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Window = '15'' at line 1
This only happens if I use a two or more keys in the formatter:
<eventFormatter name="GenericAccountSQLFormatter" statistics="enable"
trace="enable" xmlns="http://wso2.org/carbon/eventformatter">
<from streamName="GenericAccountMeasureStream" version="1.0.0"/>
<mapping customMapping="disable" type="map"/>
<to eventAdaptorName="APCSQLOut" eventAdaptorType="mysql">
<property name="table.name">AccountStats</property>
<property name="update.keys">AccountId,Window</property>
<property name="execution.mode">insert-or-update</property>
</to>
</eventFormatter>
Removing either of the keys (AccountId, Window) then the formatter will send data to MySQL.
Can anyone help?
This is a bug and happens when existing events are sent to a MySQL adaptor with composite keys. Created a jira to track this and the source patch is also available there.
If you don't want to create/apply a patch, then as a quick workaround for now - you can output a composite key from CEP query by concatenating the two attributes and use that as the key in formatter.
UPDATE
The source patch with the fix and build instructions are now available in the jira here. Once built, you need to apply it as a patch to CEP. To apply it as a patch, create a directory named patch0xyz ( xyz are digits as in patch0135, also make xyz > 100) in <CEP>/repository/components/patches and then place the jar inside it. Then you need to rename the jar as org.wso2.carbon.event.output.adaptor.mysql_1.0.1.jar. Then restart the server.
Related
We are trying to save JSON string to the database column defined as CLOB. We get the below error:
Caused by: java.sql.SQLIntegrityConstraintViolationException: ORA-02290: check constraint (MYSCHEMA.MY_JSON_CHK) violated
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:466)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:407)
at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:1113)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:546)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:269)
at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:603)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:234)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:55)
at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:1006)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1316)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:5010)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:5136)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeUpdate(OraclePreparedStatementWrapper.java:1519)
at weblogic.jdbc.wrapper.PreparedStatement.executeUpdate(PreparedStatement.java:170)
Version: Weblogic 12.2.1.2
Attempted two data types at application ORM layer for this column
java.sql.Clob & oracle.jbo.domain.ClobDomain
Direct update via SQL works good
Enabled & Disabled wrapping of datatype in weblogic
JDBC datasource.
I attempted to switch my EO (ORM) attribute from oracle.jbo.ClobDomain back to a plain String and this worked.
I have the exact same database definition for multiple databases ( and database servers ). How do I tell Jooq to use the same database as the "Connection" I created to connect to the DB?
Example ( for MySQL ):
jdbc:mysql://localhost:3306/tsm - my development DB ( tsm ), used to generate code
jdbc:mysql://RemoteAmazonDBHost:3306/customer1 - one of my customers
jdbc:mysql://RemoteAmazonDBHost:3306/customer2 - Another customer
All 3 databases have the same definition, the same tables, indexes, etc. The TSM one is the standard our application uses.
Maybe I should be using DSL.using( Connection, Setting ) instead of DSL.using(Connection)? Is that what the manual is implying here?
If I only have one "Input" schema, do I have to specify it? In other words, can I do something like this:
Settings settings = new Settings()
.withRenderMapping(new RenderMapping()
.withSchemata(
new MappedSchema().withOutput(
databaseInfo.getProperties().getProperty("database.db"))));
Or do I have to do something like this:
Settings settings = new Settings()
.withRenderMapping(new RenderMapping()
.withSchemata(
new MappedSchema().withInput("TSM")
.withOutput(databaseInfo.getProperties().getProperty("database.db"))));
I'm assuming you're using code generation. In that case, it might be the easiest to not generate the schema at all but use <outputSchemaToDefault> in the code generation configuration, e.g.
<configuration>
<generator>
<database>
<inputSchema>your_codegen_input_schema_here</inputSchema>
<outputSchemaToDefault>true</outputSchemaToDefault>
</database>
</generator>
</configuration>
See the manual for details: https://www.jooq.org/doc/latest/manual/code-generation/codegen-advanced/codegen-config-database/codegen-database-catalog-and-schema-mapping/
If you want to keep your generated code with schema qualification and map things at runtime, then your second attempt seems correct. Pass this to your Configuration (i.e. the DSL.using() call):
Settings settings = new Settings()
.withRenderMapping(new RenderMapping()
.withSchemata(new MappedSchema()
.withInput("TSM")
.withOutput(databaseInfo.getProperties().getProperty("database.db"))));
More details can be found here: https://www.jooq.org/doc/latest/manual/sql-building/dsl-context/custom-settings/settings-render-mapping
I am generating deployment-files for my mysql-database with phing and dbdeploy.
The output of a dbdeploy-file that is generated looks like the following:
-- Fragment begins: 8 --
INSERT INTO changelog
(change_number, delta_set, start_dt, applied_by, description) VALUES (8, 'Main', NOW(), 'dbdeploy', '8-add_tracking_code.sql');
--//
ALTER TABLE `order` ADD `tracking_code` VARCHAR(255) NOT NULL;
UPDATE changelog
SET complete_dt = NOW()
WHERE change_number = 8
AND delta_set = 'Main';
-- Fragment ends: 8 --
The Problem is the --// before the ALTER Statement. The database got an error with it. If I remove the --// the hole file ist correct.
Here is a piece of my phing build-script so that you can see how I am generating the .sql-File with dbdeploy:
<target name="dbdeploy-migrate-all">
<!-- load the dbdeploy task -->
<taskdef name="dbdeploy" classname="phing.tasks.ext.dbdeploy.DbDeployTask"/>
<echo message="Loading deltas from ${build.dbdeploy.alters_dir}" />
<property name="build.dbdeploy.deployfile" value="${build.dbdeploy.deploy_dir}/deploy-${DSTAMP}${TSTAMP}.sql" />
<property name="build.dbdeploy.undofile" value="${build.dbdeploy.undo_dir}/undo-${DSTAMP}${TSTAMP}.sql" />
<!-- generate the deployment scripts -->
<dbdeploy
url="mysql:host=${db.host};dbname=${db.name}"
userid="${db.user}"
password="${db.pass}"
dir="${build.dbdeploy.alters_dir}"
outputfile="${build.dbdeploy.deployfile}"
undooutputfile="${build.dbdeploy.undofile}" />
<!-- execute the SQL - Use mysql command line to avoid trouble with large files or many statements and PDO -->
<property name="mysql.command" value="${progs.mysql} -h${db.host} -u${db.user} -p${db.pass} ${db.name} < ${build.dbdeploy.deployfile}" />
<echo message="Executing command: ${mysql.command}" />
<exec
command="${mysql.command}"
dir="${base.path}"
checkreturn="true" />
</target>
Why does dbdeploy generate a corrupt file?
Thans for your help!
A long time has passed since this question was asked, however I ran into the same problem and have managed to work out where Niels is coming from on this one.
I think we both ran into the problem because we both followed the popular tutorial on phing and dbdeploy by Dave Marshall here: http://davedevelopment.co.uk/2008/04/14/how-to-simple-database-migrations-with-phing-and-dbdeploy.html
In his example sql delat file he includes --// at the top which, if replaced with a comment in /* .... */ format instead, avoids this problem!
So I would say this is a bug in the tutorial, which is 8 years old now. Dave notes at the top of the tutorial that about 4 years ago he moved onto a different method, so it is kind of understandable that there is now a bug in the tutorial! I will submit a comment requesting an update though, because his page is a top ranking search result when searching for the topic so it would be good if we can save people the same problem we've had!
It is a shame phing didn't give a more detailed error report in the form of the SQL exception - there's an idea for a contribution to the dbdeploy script!
I am using Hibernate3 with spring application.
I introduced a column in my existing table with many to one relationship with the addition in the .hbm file as mentioned below:
<many-to-one name="qualityStatus" column="quality_status"
class="model.PurchaseStatus" lazy="false" fetch="join"/>
The corresponding object to this hbm has a property of type 'PurchaseStatus' and field name as 'qualityStatus'.
Now when i try fetching the data from the table representing the above object with the query:
List<Long> dnIds = session.createQuery("select dnItem.dnId from DeliveryNoteItem dnItem where dnItem.qualityStatus!=? and dnItem.qualityStatus!=? and dnItem.qualityStatus!=?")
.setInteger(0,1)
.setInteger(1,5)
.setInteger(2,7)
.list();
i get an error saying as 'java.sql.Exception: Unknown column 'deliveryno0_.quality_status' in 'where clause'
I get this error when deployed on test server but when i check the same thing on my local server i works fine as well when i just run this query directly on the database on the test server it returns me result. So it confirms that the database on the test server is alright. It is only when it executes through the application on the test server i am getting this error.
Can anybody let me know what can be the reason or how do i debug this out.
Thanks in advance. Looking forward for replies.
If you really have a quality_status column in your database, then you should make sure you have the most recent version of your application deployed on the test server, and make sure that the connection url of hibernate really points to the test database.
This is not a hibernate problem, not a programming one. It is environmental - check your configurations and redeploy.
I have a lot of services which query the database. All of them work fine but one service calling a stored procedure gives me following error:
Could not find server 'dbo' in
sys.servers. Verify that the correct
server name was specified. If
necessary, execute the stored
procedure sp_addlinkedserver to add
the server to sys.servers.
I have not idea why all the other stored procedures work fine and this one not...
By the way, I use SubSonic as data access layer.
Please run select name from sys.servers from the server which you mentioned as default server in configuration file.
Here in name column values should match with your server names used in the report query.
e.g serverXXX.databasename.schema.tablename
serverXXX should be there in the result of select name from sys.servers otherwise it gives error as got.
It sounds like there is an extra "." (or two) in the mapping - i.e. it is trying to find server.database.schema.object. Check your mapping for stray dots / dubious entries.
Also make sure that the server name matches what you think it is. If you rename the host that SQL Server is running on, you need to rename the SQL Server, too.
http://www.techrepublic.com/blog/datacenter/changing-the-name-of-your-sql-server/192
I had another issue with the same exception so I'll post here if someone stumble upon it:
Be careful if you specify the server name in synonyms. I had a different server name on my staging machine and production and it caused the same 'cannot find server'-error.
(Guess you shouldn't use synonyms that much anyway but it's useful in some migration scenarios)
In my case i was facing same issue with following ,
SqlCommand command = new SqlCommand("uspx_GetTemplate", connection);
but after adding square bracket to stored procedure name it get solved.
SqlCommand command = new SqlCommand("[uspx_GetTemplate]", connection);