java - HibernateQueryException with mapping a class with a composite key with Hibernate version 2.1.7 -


i'm maintaining old software using hibernate 2.1.7c version (released 2004) object-relational mapping mysql-database. database table old , contains following columns:

remoteid bigint(20) label    varchar(255) locale   varchar(255) primary key ('remoteid', 'locale') 

i'm trying create new class uses hibernate-mapping file map columns. mapping-file looks this:

localizednames.hbm.xml <?xml version="1.0"?> <!doctype hibernate-mapping public         "-//hibernate/hibernate mapping dtd 2.0//en"         "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd"> <hibernate-mapping>     <class name="package.package.localizednames" table="localizednames">         <composite-id>             <key-property access="field" column="remoteid" name="remoteid" type="java.lang.long"/>             <key-property access="field" column="locale" name="locale" type="java.lang.string"/>         </composite-id>         <property column="label" name="label" not-null="true" access="field" type="java.lang.string"/>     </class> </hibernate-mapping> 

i've tried read old hibernate reference -book bit catch how should working. book says this:

your persistent class must override equals() , hashcode() implement composite identifier equality.  must implements serializable. 

so how class looks like:

public class localizednames implements serializable {     private static final long serialversionuid = 7526472295622776147l;     private long remoteid;     private string label;     private string locale;     /*getters , setters each field*/      @override     public boolean equals(object o) {         if (o == null) return false;         if (getclass() != o.getclass()) return false;         localizednames obj = (localizednames) o;          if (obj.remoteid == this.remoteid &&                 obj.locale.equals(this.locale)) {             return true;         }          return false;     }      @override     public int hashcode() {         return new hashcodebuilder(5, 25).                 append(label).                 tohashcode();     } } 

okay, that's implementation class , hibernate-mapping. now, when i'm trying data class extends hibernatedaosupport, i'm getting hibernatequeryexception doesn't me much. query this:

public class localizednamedao extends basedao {     public list findallchoicelocalizednames(string locale) {         list result = gethibernatetemplate().find("from localizednames ln ln.locale=?", locale);         return result;     }   }   public class basedao extends hibernatedaosupport { ... } 

and stack trace i'm getting this:

org.springframework.orm.hibernate.hibernatequeryexception: in expected: ln [from localizednames ln ln.locale=?]; nested exception net.sf.hibernate.queryexception: in expected: ln [from localizednames ln ln.locale=?] net.sf.hibernate.queryexception: in expected: ln [from localizednames ln ln.locale=?]     @ net.sf.hibernate.hql.fromparser.token(fromparser.java:102)     @ net.sf.hibernate.hql.clauseparser.token(clauseparser.java:87)     @ net.sf.hibernate.hql.preprocessingparser.token(preprocessingparser.java:123)     @ net.sf.hibernate.hql.parserhelper.parse(parserhelper.java:29)     @ net.sf.hibernate.hql.querytranslator.compile(querytranslator.java:149)     @ net.sf.hibernate.hql.querytranslator.compile(querytranslator.java:138)     @ net.sf.hibernate.impl.sessionfactoryimpl.getquery(sessionfactoryimpl.java:295)     @ net.sf.hibernate.impl.sessionimpl.getqueries(sessionimpl.java:1571)     @ net.sf.hibernate.impl.sessionimpl.find(sessionimpl.java:1542)     @ net.sf.hibernate.impl.queryimpl.list(queryimpl.java:39)     @ org.springframework.orm.hibernate.hibernatetemplate$25.doinhibernate(hibernatetemplate.java:641)     @ org.springframework.orm.hibernate.hibernatetemplate.execute(hibernatetemplate.java:312)     @ org.springframework.orm.hibernate.hibernatetemplate.find(hibernatetemplate.java:631)     @ org.springframework.orm.hibernate.hibernatetemplate.find(hibernatetemplate.java:626)     ... more stack trace ... 

so, knows i'm doing wrong here? i'm not familiar old hibernate versions , never used composite keys before, might simple. exception , cause gives doesn't give me information eather. issue seems hibernate mapping -file, can't pinpoint is.

thanks answers :)

managed 1 sorted, simple issue said, missing necessary configuration :)


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -