[cosmo-dev] Cosmo server Mysql 4.1

De Massis Fabrizio f.demassis at sysonline.info
Wed Jul 9 10:07:56 PDT 2008


I'm trying to use cosmo server 0.16.0 with mysql Database release 
4.1.11a-4 on Debian Sarge.
First I created a database with UTF8 option, but when starting cosmo 
server creates database objects results the following error:

2008-07-09 18:42:26,236 INFO  [DbInitializer] Creating database
2008-07-09 18:42:27,420 WARN  [AnnotationSessionFactoryBean] 
Unsuccessful schema statement: create table attribute (attributetype 
varchar(16) not null, id bigint not null auto_increment, createdate 
bigint, etag varchar(255), modifydate bigint, localname varchar(255) not 
null, namespace varchar(255) not null, binvalue longblob, booleanvalue 
bit, datevalue datetime, tzvalue varchar(32), decvalue decimal(19,6), 
textvalue longtext, intvalue bigint, stringvalue varchar(2048), itemid 
bigint not null, primary key (id), unique (itemid, namespace, 
localname)) ENGINE=InnoDB
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Specified key was 
too long; max key length is 1024 bytes

I used this configuration in 
OSAFSRV_HOME/tomcat/conf/Catalina/localhost/chandler.xml for database 
connection.

        <!-- MySQL UTF8
  <Resource name="jdbc/cosmo" type="javax.sql.DataSource" maxActive="100"
            maxIdle="30" maxWait="10000" username="cosmo"
            password="_Cosm0_" defaultAutoCommit="false"
            driverClassName="com.mysql.jdbc.Driver"
            
url="jdbc:mysql://mysql.server.tld:3306/cosmo?useUnicode=true&amp;characterEncoding=UTF8" 
/>

Just a little googling and I discovered this sort of explanatione:

some of the text field exceeds 1024 character limit due to UTF8 using 3 
bytes for each character in Mysql 4.1.x. I suppose is due to the 
composed key (itemid, namespace, localname).


I tried to avoid UTF8 using creating the database with latin1 character 
set and configuring connection in 
OSAFSRV_HOME/tomcat/conf/Catalina/localhost/chandler.xml this way:


        <!-- MySQL latin1
  <Resource name="jdbc/cosmo" type="javax.sql.DataSource" maxActive="100"
            maxIdle="30" maxWait="10000" username="cosmo"
            password="_Cosm0_" defaultAutoCommit="false"
            driverClassName="com.mysql.jdbc.Driver"
            
url="jdbc:mysql://mysql.server.tld:3306/cosmo?useUnicode=true&amp;characterEncoding=latin1" 
/>


It works fine for the first time. When I restart the cosmo server I 
receive this error:

2008-07-09 18:55:07,553 INFO  [Catalina] Initialization processed in 2111 ms
2008-07-09 18:55:14,098 INFO  [LifecycleLoggerListener] Chandler Server 
0.16.0 starting
2008-07-09 18:55:26,466 INFO  [CosmoPropertyPlaceholderConfigurer] 
Loading properties file from URL [file:etc/cosmo.properties]
2008-07-09 18:56:47,743 INFO  [DbInitializer] found schema version 160
2008-07-09 18:56:47,761 INFO  [DbInitializer] validating schema
2008-07-09 18:56:48,357 ERROR [DbInitializer] error validating schema
org.hibernate.HibernateException: Wrong column type in cosmo.attribute 
for column stringvalue. Found: text, expected: varchar(2048)
        at org.hibernate.mapping.Table.validateColumns(Table.java:261)
        at 
org.hibernate.cfg.Configuration.validateSchema(Configuration.java:1089)
        at 
org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:116)
        at 
org.osaf.cosmo.db.DbInitializer.validateSchema(DbInitializer.java:164)
        at org.osaf.cosmo.db.DbInitializer.initialize(DbInitializer.java:85)
        at 
org.osaf.cosmo.db.DbListener.contextInitialized(DbListener.java:58)
        at 
org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3729)
        at 
org.apache.catalina.core.StandardContext.start(StandardContext.java:4187)
        at 
org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:759)
        at 
org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:739)
        at 
org.apache.catalina.core.StandardHost.addChild(StandardHost.java:524)
        at 
org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:608)
        at 
org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:535)
        at 
org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:470)
        at 
org.apache.catalina.startup.HostConfig.start(HostConfig.java:1122)
        at 
org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:310)
        at 
org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
        at 
org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1021)
        at 
org.apache.catalina.core.StandardHost.start(StandardHost.java:718)
        at 
org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1013)
        at 
org.apache.catalina.core.StandardEngine.start(StandardEngine.java:442)
        at 
org.apache.catalina.core.StandardService.start(StandardService.java:450)
        at 
org.apache.catalina.core.StandardServer.start(StandardServer.java:709)
        at org.apache.catalina.startup.Catalina.start(Catalina.java:551)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:294)
        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:432)



I Found on mysql manual that varchar(n) fields with n>255 are 
automatically converted in the correct text type, so the hibernate 
validation fails.
I tryed to change hibernate .xbm configuration file for the class 
Attribute in the model but I can't find any, and I think hibernate 
configuration is in the Java source code as annotations.

Any suggestion how to solve this problem?


Thanks in advance,
Fabrizio De Massis


More information about the cosmo-dev mailing list