-->
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: Wrong SQL query: ElementCollection included as column
PostPosted: Thu Feb 16, 2012 3:01 pm 
Newbie

Joined: Mon Feb 13, 2012 1:55 pm
Posts: 4
I have this field in an Entity class, which a collection of String's:

Code:
    @ElementCollection(fetch=FetchType.EAGER)
    @JoinTable(name="wifi_network_config_auth_algorithm")
    @JoinColumn(name="wifi_network_config_id", referencedColumnName="id")
    private ArrayList<String> authAlgorithm = new ArrayList<String>();

    public List<String> getAuthAlgorithm() {
        return authAlgorithm;
    }

    public void setAuthAlgorithm(ArrayList<String> authAlgorithm) {
        this.authAlgorithm = authAlgorithm;
    }


When I use HibernateTemplate.find("from wifi_network_config") the query below is generated & causes SQLGrammarException as the column corresponding to the field 'authAlgorithm' is not in the database table. Since authAlgorithm is a collection, it should be not included in the query.

Code:
2012-02-16 10:11:56,365 WARN - <SQL Error: 1054, SQLState: 42S22>
2012-02-16 10:11:56,366 ERROR - <Unknown column 'wifinetwor0_.authAlgorithm' in 'field list'>
org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute query; SQL [select wifinetwor0_.id as id0_, wifinetwor0_.ssid as ssid0_, wifinetwor0_.priority as priority0_, wifinetwor0_.auth_algorithms as auth4_0_, wifinetwor0_.group_cipher as group5_0_, wifinetwor0_.key_management as key6_0_, wifinetwor0_.pairwise_cipher as pairwise7_0_, wifinetwor0_.protocol as protocol0_, wifinetwor0_.vpn_type as vpn9_0_, wifinetwor0_.vpn_url as vpn10_0_, wifinetwor0_.authAlgorithm as authAlg11_0_ from wifi_network_config wifinetwor0_]; nested exception is org.hibernate.exception.SQLGrammarException: could not execute query
        at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:629)
        at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
        at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:411)
        at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
        at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:912)
        at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:904)


Database is MySql. This works in a small test program that's run against hsqldb.

Thanks,
Hari


Top
 Profile  
 
 Post subject: Re: Wrong SQL query: ElementCollection included as column
PostPosted: Fri Feb 17, 2012 5:02 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Quote:
This works in a small test program that's run against hsqldb.


Do you mean, that your example is working well with hsqldb whilst the exact same example with mysql gives this error ?

If yes, please check if you are using the correct hibernate.dialect when working with mysql ...


Top
 Profile  
 
 Post subject: Re: Wrong SQL query: ElementCollection included as column
PostPosted: Fri Feb 17, 2012 2:42 pm 
Newbie

Joined: Mon Feb 13, 2012 1:55 pm
Posts: 4
Thanks for the response. The sample program that works is a small standalone program. The one that breaks is a web application. The code is different, but they use the same persistence annotations for their collection fields.

The dialect is set correctly as you can see from the bean definition below.

Code:
   <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" destroy-method="destroy">
        <property name="annotatedClasses">
            <list>
                <value>com.smobilesystems.wifi_offload.model.WifiNetworkConfig</value>
                <value>com.smobilesystems.wifi_offload.model.AuthAlgorithm</value>
            </list>
        </property>

        <property name="dataSource">
            <ref bean="dataSource"/>
        </property>

        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                <prop key="hibernate.connection.release_mode">after_statement</prop>
                <prop key="hibernate.show_sql">true</prop>
            </props>
        </property>
    </bean>


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.