I'm trying to use hibernate 3.2.6 to query data from a single table "App" in a legacy MySQL 5 DB. First, I used hibernate tools 3.2.2Beta1 to reverse engineer my domain objects. When I execute a simple query, i get a strange IllegalArgumentException error..
My domain object is simply:
Code:
public class App implements java.io.Serializable {
private Integer appSeq;
private String version;
private String name;
public App() {
}
public Integer getAppSeq() {
return this.appSeq;
}
public void setAppSeq(Integer appSeq) {
this.appSeq = appSeq;
}
public String getVersion() {
return this.version;
}
public void setVersion(String version) {
this.version = version;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
}
and the mapping file is:
Code:
<hibernate-mapping>
<class name="com.mycompany.app.ras.domain.studio.App" table="App" catalog="frmsrv_wishbone">
<id name="appSeq" type="java.lang.Integer">
<column name="AppSeq" />
<generator class="identity" />
</id>
<property name="version" type="string">
<column name="version" length="20" not-null="true" unique="true" />
</property>
<property name="name" type="string">
<column name="Name" length="40" not-null="true" />
</property>
</class>
</hibernate-mapping>
The code is:
Code:
try {
SessionFactory sessionFactory = new Configuration()
.configure()
.buildSessionFactory();
Session session = sessionFactory.openSession();
List<App> apps = session.createQuery("from App").list();
} catch (HibernateException e) {
e.printStackTrace();
}
..to query from the App table:
Code:
CREATE TABLE `App` (
`AppSeq` int(11) NOT NULL auto_increment,
`Name` varchar(40) NOT NULL default '',
`Descr` mediumtext NOT NULL,
`published` char(1) NOT NULL default '0',
`version` varchar(20) NOT NULL default '',
`include_in_device_add_dropdown` char(1) NOT NULL default 'Y',
`ota_download_default_version` char(1) NOT NULL default '',
`include_in_ota_download_dropdown` char(1) NOT NULL default 'Y',
`published_date` datetime default NULL,
PRIMARY KEY (`AppSeq`),
UNIQUE KEY `version` (`version`)
) ENGINE=MyISAM AUTO_INCREMENT=60 DEFAULT CHARSET=latin1
I get the following error:
Code:
org.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling setter of com.mycompany.app.ras.domain.studio.App.version
at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:104)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.setPropertyValues(AbstractEntityTuplizer.java:337)
at org.hibernate.tuple.entity.PojoEntityTuplizer.setPropertyValues(PojoEntityTuplizer.java:200)
at org.hibernate.persister.entity.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:3571)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:133)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:854)
at org.hibernate.loader.Loader.doQuery(Loader.java:729)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2213)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at test.mycompany.app.ras.domain.studio.HibernateTest.testLoadApplication(HibernateTest.java:40)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:164)
at junit.framework.TestCase.runBare(TestCase.java:130)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:120)
at junit.framework.TestSuite.runTest(TestSuite.java:230)
at junit.framework.TestSuite.run(TestSuite.java:225)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:42)
... 34 more
I thought this might have to do with the version field in particular, so I removed it from the mapping file completed. however, instead I get the same exact type of error on the name field.
Then i looked at the hibernate generated logs and see the following right before the error occurs:
Code:
08-18 15:05:17,439 ERROR main org.hibernate.property.BasicPropertyAccessor - IllegalArgumentException in class: com.mycompany.app.ras.domain.studio.App, setter method of property: version
08-18 15:05:17,439 ERROR main org.hibernate.property.BasicPropertyAccessor - expected type: com.mycompany.app.ras.domain.studio.String, actual value: java.lang.String
What could be wrong here? Why would hibernate expect the value to be of type com.mycompany.app.ras.domain.studio.String instead of java.lang.String?