-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Hibernate Mysql Exception
PostPosted: Mon Oct 03, 2011 6:29 am 
Newbie

Joined: Sun Oct 02, 2011 3:27 pm
Posts: 1
Hi All,

I'm developing a project with spring 3.0.5 and hibernate 3.6.0.

My application-context.xml is below:

........
.......

<context:annotation-config />
<context:component-scan base-package="com.bogazici.swe574" />
<context:property-placeholder location="classpath:jdbc.properties" />
<tx:annotation-driven transaction-manager="transactionManager"/>

<bean id="jspViewResolver"
class="org.springframework.web.servlet.view.Intern alResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlVi ew" />
<property name="prefix" value="/WEB-INF/pages/" />
<property name="suffix" value=".jsp" />
</bean>

<bean id="messageSource"
class="org.springframework.context.support.Reloada bleResourceBundleMessageSource">
<property name="basename" value="classpath:messages" />
<property name="defaultEncoding" value="UTF-8" />
</bean>

<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverM anagerDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.databaseurl}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotati on.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<list> <value>com.bogazici.swe574.model.Contact</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${jdbc.dialect}</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.ejb.naming_strategy">org.hibernate. cfg.ImprovedNamingStrategy</prop>
</props>
</property>
</bean>

<bean id="transactionManager" class="org.springframework.orm.hibernate3.Hibernat eTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
</beans>



When I start my serve I got the error below:


Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorEx ception: Unknown table 'sequences' in information_schema
at sun.reflect.NativeConstructorAccessorImpl.newInsta nce0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInsta nce(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newI nstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:41 1)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLErro r.java:1052)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.ja va:3597)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.ja va:3529)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:19 90)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java :2151)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionIm pl.java:2619)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionIm pl.java:2569)
at com.mysql.jdbc.StatementImpl.executeQuery(Statemen tImpl.java:1521)
at org.hibernate.tool.hbm2ddl.DatabaseMetadata.initSe quences(DatabaseMetadata.java:151)
at org.hibernate.tool.hbm2ddl.DatabaseMetadata.<init> (DatabaseMetadata.java:69)
at org.hibernate.tool.hbm2ddl.DatabaseMetadata.<init> (DatabaseMetadata.java:62)
at org.springframework.orm.hibernate3.LocalSessionFac toryBean$1.doInHibernate(LocalSessionFactoryBean.j ava:940)
at org.springframework.orm.hibernate3.HibernateTempla te.doExecute(HibernateTemplate.java:406)


How can I resolve this error?

Thank you very much.


Top
 Profile  
 
 Post subject: Re: Hibernate Mysql Exception
PostPosted: Mon Oct 24, 2011 5:56 am 
Newbie

Joined: Mon Oct 24, 2011 5:49 am
Posts: 2
I have the same problem: I'm trying to execute a little demo of Spring + Hibernate using MySQL as database and I'm not able to run it (same code using H2 works perfect).

app-context.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
   xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
   xsi:schemaLocation="
      http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
      http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
      http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">


    <import resource="hibernate.xml" /> 

   <tx:annotation-driven transaction-manager="transactionManager" />
   
   <context:component-scan base-package="edu.elpasmo.spring" />

</beans>


hibernate.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="
      http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
      
   <bean
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location">
            <value>META-INF/spring/application.properties</value>
        </property>
    </bean>

    <bean id="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="${jdbc.driverClassName}" />
        <property name="url" value="${jdbc.url}" />
        <property name="username" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />
    </bean>

    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">

        <property name="dataSource" ref="dataSource" />
        <property name="annotatedClasses">
            <list>
                <value>edu.elpasmo.spring.hibernate.model.Element</value>
            </list>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.hbm2ddl.auto">create</prop>
            </props>
        </property>
    </bean>
</beans>


Element.java
Code:
@Entity
public class Element {
   private Integer elementId;
   
   public Element() {

   }
   
   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   @Column(name = "ID")
   public Integer getElementId() {
      return elementId;
   }
   public void setElementId(Integer elementId) {
      this.elementId = elementId;
   }
}


The table is created right. The problem is in the first insert: Unknown table 'sequences' in information_schema.

My system:
Ubuntu 11.04 64 bits
STS 2.8.0
mysql-connector-java 5.1.10 (I'd also tried with version 5.10.18).
MySQL Version 5.1.54
openjdk-6-jdk Version 6b22-1.10.2

I've tried with all the GenerationType for Element.id (SEQUENCE, IDENTITY, etc...).
I've tried switching to a H2 database and works perfectly.
I've tried also upgrading Hibernate from 3.6.0 to 3.6.7 with no joy.

Console
Code:
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'elementDao': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void edu.elpasmo.spring.hibernate.dao.ElementDAO.setSessionFactory(org.hibernate.SessionFactory); nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactoryBean' defined in class path resource [edu/elpasmo/spring/HibernateConfiguration.class]: Invocation of init method failed; nested exception is org.springframework.jdbc.BadSqlGrammarException: Hibernate-related JDBC operation; bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown table 'sequences' in information_schema
           at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:288)
           at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1074)
           at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
           at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
           at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)
           at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
           at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)
           at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192)
           at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
           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.<init>(ClassPathXmlApplicationContext.java:139)
           at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
           at edu.elpasmo.spring.hibernate.app.RunHibernate.main(RunHibernate.java:17)
        Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void edu.elpasmo.spring.hibernate.dao.ElementDAO.setSessionFactory(org.hibernate.SessionFactory); nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactoryBean' defined in class path resource [edu/elpasmo/spring/HibernateConfiguration.class]: Invocation of init method failed; nested exception is org.springframework.jdbc.BadSqlGrammarException: Hibernate-related JDBC operation; bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown table 'sequences' in information_schema
           at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:595)
           at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
           at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:285)
           ... 13 more
        Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactoryBean' defined in class path resource [edu/elpasmo/spring/HibernateConfiguration.class]: Invocation of init method failed; nested exception is org.springframework.jdbc.BadSqlGrammarException: Hibernate-related JDBC operation; bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown table 'sequences' in information_schema
           at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420)
           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:293)
           at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
           at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)
           at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192)
           at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:848)
           at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:790)
           at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:707)
           at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:553)
           ... 15 more
        Caused by: org.springframework.jdbc.BadSqlGrammarException: Hibernate-related JDBC operation; bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown table 'sequences' in information_schema
           at org.springframework.jdbc.support.SQLExceptionSubclassTranslator.doTranslate(SQLExceptionSubclassTranslator.java:94)
           at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
           at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
           at org.springframework.orm.hibernate3.HibernateAccessor.convertJdbcAccessException(HibernateAccessor.java:442)
           at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:414)
           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)
           ... 25 more
        Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown table 'sequences' in information_schema
           at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
           at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
           at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
           at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
           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.ConnectionImpl.execSQL(ConnectionImpl.java:2568)
           at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1557)
           at org.hibernate.tool.hbm2ddl.DatabaseMetadata.initSequences(DatabaseMetadata.java:151)
           at org.hibernate.tool.hbm2ddl.DatabaseMetadata.<init>(DatabaseMetadata.java:69)
           at org.hibernate.tool.hbm2ddl.DatabaseMetadata.<init>(DatabaseMetadata.java:62)
           at org.springframework.orm.hibernate3.LocalSessionFactoryBean$1.doInHibernate(LocalSessionFactoryBean.java:940)
           at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406)
           ... 31 more


Top
 Profile  
 
 Post subject: Re: Hibernate Mysql Exception
PostPosted: Mon Oct 24, 2011 7:59 am 
Newbie

Joined: Mon Oct 24, 2011 5:49 am
Posts: 2
They just solved my problem in the following link: http://forum.springsource.org/showthrea ... a&p=384575

I started my demo with the template "Simple Spring Hibernate Utility Project" and it creates a HibernateConfiguration.class that was the cause of my problem. Deleting it from the project solved it.

Maybe is the same issue for you?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.