Tuesday, 12 October 2010

inconsistent datatypes with JPA.. eish

I've been having some weird errors with JPA eg.
(pasted here so you can find it with google)
==
INFO - batching 1 statements: 1: insert into dds.DDS_EMAIL_STATUS (DOC_REGISTER_ID, EMAIL_ADDRESS_FROM,
EMAIL_ADDRESS_TO, LAST_UPDATE_TIME, MESSAGE_ID, SEND_DATETIME, STATUS_ID, SUBJECT, DDS_EMAIL_STATUS_ID)
values (1001, 'dds-test@example.com', 'test@example.com', to_date('10/12/2010 12:41:05', 'mm/dd/yyyy
hh24:mi:ss'), NULL, to_date('10/12/2010 12:41:05', 'mm/dd/yyyy hh24:mi:ss'), 0, 'testSend',
800)  {executed in 4 msec}
INFO - executeBatch()
ERROR - 2. PreparedStatement.executeBatch() batching 2 statements:
1:  insert into dds.DDS_EMAIL_STATUS_LOG (DATE_TIME, DDS_EMAIL_STATUS_ID, MESSAGE, DDS_EMAIL_STATUS_LOG_ID) values (to_date('10/12/2010 12:41:05', 'mm/dd/yyyy hh24:mi:ss'), '', 'html body:
html body', 750)
java.sql.BatchUpdateException: ORA-00932: inconsistent datatypes: expected NUMBER got BINARY
    at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:343)
    at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10720)
    at net.sf.log4jdbc.StatementSpy.executeBatch(StatementSpy.java:523)
    at org.apache.commons.dbcp.DelegatingStatement.executeBatch(DelegatingStatement.java:297)
    at org.apache.commons.dbcp.DelegatingStatement.executeBatch(DelegatingStatement.java:297)
    at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
    at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
    at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
    at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
    at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
    at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
    at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
    at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:304)
    at org.apache.openejb.persistence.JtaEntityManager.flush(JtaEntityManager.java:130)
==
java.sql.SQLException: incompatible data types in combination in statement [alter table DDS_EMAIL_STATUS_LOG add constraint FKB7F2A8E6BAAD6FBB foreign key (DDS_EMAIL_STATUS_ID) references DDS_EMAIL_STATUS]
 at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
 at org.hsqldb.jdbc.JDBCStatement.fetchResult(Unknown Source)
 at org.hsqldb.jdbc.JDBCStatement.executeUpdate(Unknown Source)
 at net.sf.log4jdbc.StatementSpy.executeUpdate(StatementSpy.java:694)
 at org.apache.commons.dbcp.DelegatingStatement.executeUpdate(DelegatingStatement.java:228)
 at org.apache.commons.dbcp.DelegatingStatement.executeUpdate(DelegatingStatement.java:228)
 at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:383)
 at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:341)
 at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:262)
 at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:211)
 at org.hibernate.impl.SessionFactoryImpl.(SessionFactoryImpl.java:343)
 at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1327)
 at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)
 at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669)
...
Caused by: org.hsqldb.HsqlException: incompatible data types in combination
 at org.hsqldb.error.Error.error(Unknown Source)
 at org.hsqldb.error.Error.error(Unknown Source)
 at org.hsqldb.Table.checkColumnsMatch(Unknown Source)
 at org.hsqldb.TableWorks.checkCreateForeignKey(Unknown Source)
 at org.hsqldb.TableWorks.addForeignKey(Unknown Source)
 at org.hsqldb.ParserDDL.processAlterTableAddForeignKeyConstraint(Unknown Source)
 at org.hsqldb.ParserDDL.processAlterTable(Unknown Source)
 at org.hsqldb.ParserDDL.processAlter(Unknown Source)
 at org.hsqldb.StatementSchema.getResult(Unknown Source)
 at org.hsqldb.StatementSchema.execute(Unknown Source)
 at org.hsqldb.Session.executeCompiledStatement(Unknown Source)
 at org.hsqldb.Session.executeDirectStatement(Unknown Source)
 at org.hsqldb.Session.execute(Unknown Source)
==
javax.persistence.PersistenceException: org.hibernate.type.SerializationException: could not deserialize
    at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:614)
    at org.hibernate.ejb.AbstractEntityManagerImpl.remove(AbstractEntityManagerImpl.java:259)
    at org.apache.openejb.persistence.JtaEntityManager.remove(JtaEntityManager.java:107)
==
1:  update DDS_EMAIL_STATUS_LOG set DATE_TIME='10/12/2010 13:11:54.206', DDS_EMAIL_STATUS_ID='', MESSAGE='text body:
text body' where DDS_EMAIL_STATUS_LOG_ID=1 {FAILED after 0 msec}
java.sql.BatchUpdateException: data exception: string data, right truncation
 at org.hsqldb.jdbc.JDBCPreparedStatement.executeBatch(Unknown Source)
 at net.sf.log4jdbc.StatementSpy.executeBatch(StatementSpy.java:523)
 at org.apache.commons.dbcp.DelegatingStatement.executeBatch(DelegatingStatement.java:297)
 at org.apache.commons.dbcp.DelegatingStatement.executeBatch(DelegatingStatement.java:297)
 at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
 at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
 at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
 at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:168)
==
I tried different databases because it looked to me like the hsqldb is getting a bit confused with the column order. But in the end it turned out that I made a bit of a mistake:
I converted an embedded complex primary key to have a generated Id. In stead of annotating the referenced object with a @ManyToOne(optional = false)
it was still using @Column(name = "DDS_EMAIL_STATUS_ID"). After much debugging, googling and figuring out how to print the actual sql using http://code.google.com/p/log4jdbc-remix/ I figured out that I neglegted to change @Column to @ManyToOne.

Why is nothing ever easy ;-P

Saturday, 2 October 2010

eclipse + tomcat + maven pain again

Banging my head against the wall again today
because my app just does not want to start up :'(
Between eclipse, tomcat and maven my classpath was messed up, getting all sorts of exceptions like NoClassDefFoundError etc.

Finally I figured out again that for each project involved you have to check "Maven Dependencies"
in the "Order and Export" tab of the Java build path settings.
Then when you tell tomcat to include these projects,
it will actually include it and its dependencies.

I'm not sure how this got lost because my app used to work. Maybe when I imported the same project in
another workspace that got reset :(

Tuesday, 7 September 2010

cannot execute binary file

I had this really weird issue on Ubuntu:
* An executable works fine on my laptop.
* Then I scp it to the server.
* On the server I get the following error messsage: "cannot execute binary file"
* So after some googling I found:
You are probably trying to run a 64-bit [executable] on a 32-bit Linux system...
http://www.kods.net/transferred-to-install-oracle-9i-in-linux-the-whole-document/

Go figure. I've been so spoiled with java and python, that I forget there are still things you need to compile for the platform you want to run it on...