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