create table LOGIN(
USERNAME CHAR(12) PRIMARY KEY not null,
SESS_NUM CHAR(1),
DATA CHAR(23))
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin 2.1
http://boss.bekk.no/boss/middlegen/
http://www.hibernate.org/
-->
<class name="Login" table="LOGIN">
<id name="userName"
type="java.lang.String"
column="USERNAME">
<generator class="assigned"/>
</id>
<property
name="sessNum"
type="java.lang.String"
column="SESS_NUM"
length="1"
/>
<property
name="data"
type="java.lang.String"
column="DATA"
length="23"
/>
<!-- Associations -->
</class>
</hibernate-mapping>
public class Login implements Serializable {
private String userName;
/** nullable persistent field */
private String sessNum;
/** nullable persistent field */
private String data;
/** full constructor */
public Login(String userName, String sessNum, String data) {
this.userName = userName;
this.sessNum = sessNum;
this.data = data;
}
public Login(String userName )
{
this.userName = userName;
}
/** default constructor */
public Login() {}
public String getUserName() {
return this.userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getSessNum() {
return this.sessNum;
}
public void setSessNum(String sessNum) {
this.sessNum = sessNum;
}
public String getData() {
return this.data;
}
public void setData(String data) {
this.data = data;
}
public String toString() {
return new ToStringBuilder(this)
.toString();
}
public boolean equals(Object other)
{
if ( userName == null || other == null )
{
return( false );
}
else if ( !( other instanceof Login ) )
{
return( false );
}
else
{
return( userName.equals( ((Login)other).getUserName( ) ) );
}
}
public int hashCode( )
{
if ( userName == null )
{
return( 0 );
}
else
{
return( userName.hashCode( ) );
}
}
}
has one row with userName = 'GH' and the other 2 fields == null;
the only index is on userName and is unique and the primarykey
I am using the 3/31/2005 hibernate3.jar release
Login login = new Login( "GH" );
session.get( Login.class, login );
produces the following dump:
what did i do wrong with you tools?
java.lang.ClassCastException
at org.hibernate.type.StringType.set(StringType.java:24)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:62)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:44)
at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1042)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1104)
at org.hibernate.loader.Loader.doQuery(Loader.java:365)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:206)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1271)
at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:141)
at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:126)
at org.hibernate.persister.entity.BasicEntityPersister.load(BasicEntityPersister.java:2496)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:387)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:368)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:166)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:140)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:249)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:123)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:561)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:556)
at HibernateServer.<init>(HibernateServer.java:67)
at HibernateServer.main(HibernateServer.java:102)