-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: weird behavior with session.get( )
PostPosted: Wed Apr 06, 2005 12:30 pm 
Beginner
Beginner

Joined: Wed Oct 29, 2003 10:43 am
Posts: 38
Location: Chicago
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)

_________________
LET IT BE :)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 08, 2005 3:43 am 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
Code:
session.get( Login.class, login.getUserName());


or

Code:
session.get( Login.class, "GH");



Have a look at the API for session.get(). It takes the serializable identifier of the object as the second arg.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.