0

I wrote a mapping as like below:

<hibernate-mapping auto-import="true" default-lazy="false">
    <class name="com.saman.entity.hibernate.EmployeeEntity"
           table="Employee" optimistic-lock="version">

        <id name="id" type="java.lang.Integer" >
            <column name="Id" />
            <generator class="identity"/>
        </id>
        <timestamp name="version" source="db"/>
        <property  name="firstName">
            <column name="FirstName" sql-type="nvarchar(300)"/>
        </property>
        <property name="lastName">
            <column name="LastName" sql-type="nvarchar(300)"/>
        </property>
        <property name="employeeType">
            <column name="EmployeeType" sql-type="nvarchar(300)"/>
        </property>
        <!--
        <set name="shifts" table="Shifts" inverse="true" lazy="true" fetch="select">
            <key>
                <column name="Id" not-null="true"/>
            </key>
            <one-to-many class="com.saman.entity.hibernate.ShiftEntity"/>
        </set>
        -->
        <properties name="u1" unique="true">
            <property name="firstName"/>
            <property name="lastName"/>
            <property name="employeeType"/>
        </properties>

    </class>
</hibernate-mapping>

when I run my application an error occurs like below:

2012-05-15 17:12:38,651 -- WARN -- Unsuccessful schema statement: create table Employee (Id integer not null auto_increment, version datetime not null, FirstName nvarchar(300), LastName nvarchar(300), EmployeeType nvarchar(300), primary key (Id), unique (firstName, lastName, employeeType)) com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Specified key was too long; max key length is 1000 bytes at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at com.mysql.jdbc.Util.handleNewInstance(Util.java:411) at com.mysql.jdbc.Util.getInstance(Util.java:386) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3609) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3541) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2002) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2163) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2618) at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1749) at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1666) at com.mchange.v2.c3p0.impl.NewProxyStatement.executeUpdate(NewProxyStatement.java:64) at org.springframework.orm.hibernate3.LocalSessionFactoryBean.executeSchemaStatement(LocalSessionFactoryBean.java:1115) at org.springframework.orm.hibernate3.LocalSessionFactoryBean.executeSchemaScript(LocalSessionFactoryBean.java:1087) at org.springframework.orm.hibernate3.LocalSessionFactoryBean$1.doInHibernate(LocalSessionFactoryBean.java:942) at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406) at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:339) at org.springframework.orm.hibernate3.LocalSessionFactoryBean.updateDatabaseSchema(LocalSessionFactoryBean.java:935) at org.springframework.orm.hibernate3.LocalSessionFactoryBean.afterSessionFactoryCreation(LocalSessionFactoryBean.java:883) at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:213) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:563) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425) at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139) at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:83) at Main.main(Main.java:18)

what is the problem with it?

Im using mysql and i run it on MAMP.

1
  • 1
    Post the full stack trace, and post the code causing this exception to be thrown. Commented May 15, 2012 at 12:32

2 Answers 2

2

Specified key was too long; max key length is 1000 bytes

This error means that your unique index (firstName, lastName, employeeType) is more than 1000 bytes which is the maximum. From mysql documentation

"UTF-8 encoding of the Unicode character set using one to three bytes per character"

Therefore you can see that you have three fields of 300 length so you may have an index of size 300* 3 * 3 = 2700 > 1000

Sign up to request clarification or add additional context in comments.

Comments

2

There is known issue with MyISAM engine. You can try this link to change the engine to InnoDB:

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.