Announcement Announcement Module
Collapse
No announcement yet.
How to set NamingStrategy for AnnotationSessionFactoryBean Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to set NamingStrategy for AnnotationSessionFactoryBean

    I want to set the ImprovedNamingStrategy for tablenames. But running my Application I get following error because the columname shortname is false - it should be short_name. Obviously the Naming strategy set by my configuration is not used for resolving the tablenames otherwis the select should correctly look for short_name.
    Any Help ?

    DEBUG (SessionImpl.java:421) -after transaction completion
    Exception in thread "main" org.springframework.jdbc.BadSqlGrammarException: Hibernate operation: could not execute query; bad SQL grammar [select airport0_.id as id0_, airport0_.location as location0_, airport0_.short_name as short3_0_ from airport airport0_ where shortName=?]; nested exception is java.sql.SQLException: Unknown column 'shortName' in 'where clause'
    java.sql.SQLException: Unknown column 'shortName' in 'where clause'
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.ja va:2926)




    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

    <beans>
    <bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName" value="org.gjt.mm.mysql.Driver"/>
    <property name="url" value="jdbc:mysql:///hibernate"/>
    <property name="username" value="root"/>
    <property name="password" value="root"/>
    </bean>


    <bean id="myNamingStrategy"
    class="org.springframework.beans.factory.config.Fi eldRetrievingFactoryBean">
    <property name="staticField"><value>org.hibernate.cfg.Improv edNamingStrategy.INSTANCE</value></property>
    </bean>


    <bean id="mySessionFactory" class="org.springframework.orm.hibernate3.annotati on.AnnotationSessionFactoryBean">
    <property name="dataSource">
    <ref bean="myDataSource"/>
    </property>
    <property name="annotatedClasses">
    <list>
    <value>de.webasto.Airport</value>
    <value>de.webasto.Flight</value>
    <value>de.webasto.Passenger</value>
    </list>
    </property>
    <property name="annotatedPackages">
    <list>
    <value>de.webasto</value>
    </list>
    </property>
    <property name="namingStrategy">
    <ref bean="myNamingStrategy"/>
    </property>
    </bean>

    <bean id="myHibernateDao" class="de.webasto.HibernateDao">
    <property name="sessionFactory" ref="mySessionFactory"/>
    </bean>

    </beans>

  • #2
    using

    <property name="namingStrategy">
    <!-- <ref bean="myNamingStrategy"/>-->
    <bean id="org.hibernate.cfg.ImprovedNamingStrategy.INSTA NCE"
    class="org.springframework.beans.factory.config.Fi eldRetrievingFactoryBean"/>
    </property>

    in the ApplicationContext.xml gives same result

    Comment

    Working...
    X