I've been away from Hibernate for a while and I feel like I'm back to square one. Any help on this little test would be greatly appreciated. I'm trying to get back up to speed.
Hibernate v2.1.4, HSQLDB 1.7.2RC6b
Cheers,
Steve Maring
THE ERROR:
Code:
[junit] WARNING: SQL Error: -16, SQLState: 37000
[junit] Jun 15, 2004 8:13:52 AM net.sf.hibernate.util.JDBCExceptionReporter logExceptions
[junit] SEVERE: Wrong data type: For input string: "att" in statement [select user0_.userid as userid1_, user0_.firstname as firstname1_, user0_.lastname as lastname1_, role1_.
roleid as roleid0_, role1_.rolename as rolename0_ from user user0_ left outer join role role1_ on user0_.userid=role1_.roleid where user0_.userid=?]
THE CODE:Code:
Session session = sessionFactory.openSession();
log.debug( "querying for all users..." );
Query query = session.createQuery( "from com.att.aan.security.dao.User" );
log.debug( "iterating resultset..." );
Iterator iterator = query.iterate();
while ( iterator.hasNext() )
{
User user = (User) iterator.next();
log.info( "found user " + user.getFirstName() + " " + user.getLastName() );
}
session.close();
THE CONFIG:Code:
<hibernate-configuration>
<property name="dialect">net.sf.hibernate.dialect.HSQLDialect</property>
<property name="show_sql">false</property>
<property name="use_outer_join">true</property>
<property name="connection.username">sa</property>
<property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
<property name="connection.url">jdbc:hsqldb:hsql://localhost:9001/xdb</property>
<!-- mapping files -->
<mapping resource="com/att/aan/security/dao/Role.hbm.xml"/>
<mapping resource="com/att/aan/security/dao/User.hbm.xml"/>
</session-factory>
</hibernate-configuration>
ROLE.HBM.XML:Code:
<hibernate-mapping>
<class
name="com.att.aan.security.dao.Role"
table="role"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="roleId"
column="roleid"
type="int"
>
<generator class="increment">
</generator>
</id>
<property
name="roleName"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="rolename"
/>
</class>
</hibernate-mapping>
USER.HBM.XML:Code:
<hibernate-mapping>
<class
name="com.att.aan.security.dao.User"
table="user"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="userId"
column="userid"
type="string"
>
<generator class="assigned">
</generator>
</id>
<property
name="firstName"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="firstname"
/>
<property
name="lastName"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="lastname"
/>
<one-to-one
name="role"
class="com.att.aan.security.dao.Role"
cascade="none"
outer-join="auto"
constrained="false"
/>
</class>
</hibernate-mapping>
DB DDL:Code:
CREATE TABLE role (
roleid integer primary key,
rolename varchar(30) not null );
CREATE TABLE user (
userid varchar(30) primary key,
firstname varchar(30) not null,
lastname varchar(30) not null,
password varchar(30) not null,
roleid integer ,
FOREIGN KEY (roleid) REFERENCES role(roleid) );
INSERT INTO role VALUES ( 101, 'att_admin' );
INSERT INTO role VALUES ( 102, 'cust_admin' );
INSERT INTO user VALUES ( 'att', 'Att', 'User', 'pass', 101 );
INSERT INTO user VALUES ( 'cust', 'Cust', 'User', 'pass', 102 );