-->
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.  [ 9 posts ] 
Author Message
 Post subject: Exception when Using Gavin's EnumUserType
PostPosted: Fri Oct 28, 2005 3:59 pm 
Newbie

Joined: Tue Jan 11, 2005 6:02 pm
Posts: 13
Location: Seattle
I'm using the EnumUserType that Gavin King wrote, in http://hibernate.org/272.html.
I'm using Hibernate 3.0.

HIbernate throws a ClassNotFoundException when I try to declare my Enum as an inner class. Is there any way I can avoid having to push the Enum out to it's own classa file?

public class Doggie {
public Enum doggieStatus { // i don't want to put these enums outside the class..
BARKING,
EATING,
SCRATCHING
}
....
}


Top
 Profile  
 
 Post subject: Re: Exception when Using Gavin's EnumUserType
PostPosted: Fri Oct 28, 2005 4:36 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
mmoores wrote:
I'm using the EnumUserType that Gavin King wrote, in http://hibernate.org/272.html.
I'm using Hibernate 3.0.

HIbernate throws a ClassNotFoundException when I try to declare my Enum as an inner class. Is there any way I can avoid having to push the Enum out to it's own classa file?

public class Doggie {
public Enum doggieStatus { // i don't want to put these enums outside the class..
BARKING,
EATING,
SCRATCHING
}
....
}


How are you referencing the Enum class ?

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 28, 2005 4:55 pm 
Newbie

Joined: Tue Jan 11, 2005 6:02 pm
Posts: 13
Location: Seattle
I'm trying to make it work like this. But hibernate can't find the class when
it's nested in the POJO.

class name="ConsumerAccount" table="/*mpm*/consumer_accounts" dynamic-update="true">
....
<!-- Properties -->

<property name="status" column="status">
<type name="com.real.app.mpm.dao.hibernate.usertype.EnumUserType">
<param name="enumClassName">
com.real.app.mpm.domain.ConsumerAccount.Status
</param>
</type>
</property>
....

public class ConsumerAccount {
public enum Status {
ACTIVE,
FROZEN
};
private Status status;
public Status getStatus() {
return status;
}
public void setStatus(Status status) {
this.status = status;
}
.....
}


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 28, 2005 6:40 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
you have to refer with
com.real.app.mpm.domain.ConsumerAccount$Status


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 28, 2005 11:48 pm 
Newbie

Joined: Tue Jan 11, 2005 6:02 pm
Posts: 13
Location: Seattle
ok i got a few of these running. but then i ran into a wall when i executed the following query and got an exception. i'm not sure why hibernate would tell me
the entity is unknown when hibernate initialized the typedef w/out problems and
i also did inserts..

org.hibernate.MappingException: Unknown entity: com.real.app.mpm.domain.MicroTransaction$Status
at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:569)
at org.hibernate.impl.SessionFactoryImpl.getIdentifierType(SessionFactoryImpl.java:647)
----------------------
Code being executed:

public void postChargeMicroTransactions(BillingTransaction chargeByBtx, BillingTransaction authByBtx) {
getSession().createQuery("update MicroTransaction set status = :newstatus,"
+ " chargedByBillingTransaction = :chargedByBillingTransaction"
+ " where authorizedByBillingTransaction = :authorizedByBillingTransaction"
+ " and status = :oldstatus")
.setEntity("newstatus", MicroTransaction.Status.PENDING)
.setEntity("oldstatus", MicroTransaction.Status.APPROVED)
.setEntity("chargedByBillingTransaction", chargeByBtx)
.setEntity("authorizedByBillingTransaction", authByBtx)
.executeUpdate();
}

---------------------------------
MicroTransaction:
<hibernate-mapping package="com.real.app.mpm.domain">
<typedef name="status" class='com.real.app.mpm.dao.hibernate.usertype.EnumUserType'>
<param name="enumClassName">com.real.app.mpm.domain.MicroTransaction$Status</param>
</typedef>

<class name="MicroTransaction" table="/*mpm*/micro_transactions" dynamic-update="true">
<!-- Primary key. -->
....
<!-- Properties -->
<property name="status" column="status" type="status"/>
....

--------------------------------------
public class MicroTransaction {
public enum Status {
APPROVED,
CANCELLED,
DECLINED,
PENDING,
POSTED,
REFUNDED,
RNC
};

private long id;
private Status status;
....
}


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 29, 2005 12:20 am 
Newbie

Joined: Tue Jan 11, 2005 6:02 pm
Posts: 13
Location: Seattle
disregard last reply..
i was calling setEntity() instead of setParameter().
thanks,
--Michael


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 29, 2005 1:05 am 
Newbie

Joined: Tue Jan 11, 2005 6:02 pm
Posts: 13
Location: Seattle
so i set the binding to use setParameter() instead of setEntity() (see code postChargeMicroTransactions() i sent in the post above) and i see this in the DEBUG output.
this does not look right to me.. zero rows get updated..
what method should i use to push the enum into a bind variable?????


21:57:50,364 DEBUG [SessionImpl] executeUpdate: update MicroTransaction set status = :newstatus, chargedByBillingTransaction = :chargedByBillingTransaction where authorizedByBillingTransaction = :authorizedByBillingTransaction and status = :oldstatus
21:57:50,365 DEBUG [SerializationHelper] Starting serialization of object [PENDING]
21:57:50,365 DEBUG [SerializationHelper] Starting serialization of object [APPROVED]
21:57:50,366 DEBUG [QueryParameters] named parameters: {authorizedByBillingTransaction=com.real.app.mpm.domain.BillingTransaction#489923, newstatus=2c6d8085fef280afe3efedaef2e5e1ecaee1f0f0aeedf0edaee4efede1e9eeaecde9e3f2efd4f2e1eef3e1e3f4e9efeea4d3f4e1f4f5f38080808080808080928080f8f2808eeae1f6e1aeece1eee7aec5eef5ed8080808080808080928080f8f0f48087d0c5cec4c9cec7, oldstatus=2c6d8085fef280afe3efedaef2e5e1ecaee1f0f0aeedf0edaee4efede1e9eeaecde9e3f2efd4f2e1eef3e1e3f4e9efeea4d3f4e1f4f5f38080808080808080928080f8f2808eeae1f6e1aeece1eee7aec5eef5ed8080808080808080928080f8f0f48088c1d0d0d2cfd6c5c4, chargedByBillingTransaction=com.real.app.mpm.domain.BillingTransaction#489924}


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 29, 2005 6:51 am 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
see generated sql


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 03, 2005 3:44 pm 
Newbie

Joined: Tue Jan 11, 2005 6:02 pm
Posts: 13
Location: Seattle
Looks like hibernate was just serializing the Enum and passing the data up to the database. it works ok if i change my query to use MicroTransaction.Status.PENDING.name() instead of MicroTransaction.Status.PENDING, etc..

Why is Hibernate unable to automatically map the Enum to the varchar by calling name() or toString() for HQL updates? It works fine for session.save()/update(), but not via HQL. (rememebr, i'm using Gavin King's EnumUserType class)

getSession().createQuery("update MicroTransaction set status = :newstatus,"
+ " chargedByBillingTransaction = :chargedByBillingTransaction"
+ " where authorizedByBillingTransaction = :authorizedByBillingTransaction"
+ " and status = :oldstatus")
.setParameter("newstatus", MicroTransaction.Status.PENDING)
.setParameter("oldstatus", MicroTransaction.Status.APPROVED)
.setEntity("chargedByBillingTransaction", chargeByBtx)
.setEntity("authorizedByBillingTransaction", authByBtx)
.executeUpdate();



2005-11-03 11:28:49,313 488121 DEBUG [org.hibernate.impl.SessionImpl] (http-0.0.0.0-8080-1:) executeUpdate: update MicroTransaction set st
atus = :newstatus, chargedByBillingTransaction = :chargedByBillingTransaction where authorizedByBillingTransaction = :authorizedByBillingT
ransaction and status = :oldstatus
2005-11-03 11:28:49,313 488121 DEBUG [org.hibernate.util.SerializationHelper] (http-0.0.0.0-8080-1:) Starting serialization of object [PEN
DING]
2005-11-03 11:28:49,313 488121 DEBUG [org.hibernate.util.SerializationHelper] (http-0.0.0.0-8080-1:) Starting serialization of object [APP
ROVED]
2005-11-03 11:28:49,314 488122 DEBUG [org.hibernate.engine.QueryParameters] (http-0.0.0.0-8080-1:) named parameters: {authorizedByBillingT
ransaction=com.real.app.mpm.domain.BillingTransaction#491483, newstatus=2c6d8085fef280afe3efedaef2e5e1ecaee1f0f0aeedf0edaee4efede1e9eeaecd
e9e3f2efd4f2e1eef3e1e3f4e9efeea4d3f4e1f4f5f38080808080808080928080f8f2808eeae1f6e1aeece1eee7aec5eef5ed8080808080808080928080f8f0f48087d0c5
cec4c9cec7, oldstatus=2c6d8085fef280afe3efedaef2e5e1ecaee1f0f0aeedf0edaee4efede1e9eeaecde9e3f2efd4f2e1eef3e1e3f4e9efeea4d3f4e1f4f5f3808080
8080808080928080f8f2808eeae1f6e1aeece1eee7aec5eef5ed8080808080808080928080f8f0f48088c1d0d0d2cfd6c5c4, chargedByBillingTransaction=com.real
.app.mpm.domain.BillingTransaction#491484}
2005-11-03 11:28:49,326 488134 DEBUG [org.hibernate.hql.ast.QueryTranslatorImpl] (http-0.0.0.0-8080-1:) parse() - HQL: update MicroTransac
tion set status = :newstatus, chargedByBillingTransaction = :chargedByBillingTransaction where authorizedByBillingTransaction = :authorize
dByBillingTransaction and status = :oldstatus
2005-11-03 11:28:49,331 488139 DEBUG [org.hibernate.hql.ast.AST] (http-0.0.0.0-8080-1:) --- HQL AST ---
\-[UPDATE] 'update'
+-[FROM] 'FROM'
| \-[RANGE] 'RANGE'
| \-[IDENT] 'MicroTransaction'
+-[SET] 'set'
| +-[EQ] '='
| | +-[IDENT] 'status'
| | \-[COLON] ':'
| | \-[IDENT] 'newstatus'
| \-[EQ] '='
| +-[IDENT] 'chargedByBillingTransaction'
| \-[COLON] ':'
| \-[IDENT] 'chargedByBillingTransaction'
\-[WHERE] 'where'
\-[AND] 'and'
+-[EQ] '='
| +-[IDENT] 'authorizedByBillingTransaction'
| \-[COLON] ':'
| \-[IDENT] 'authorizedByBillingTransaction'
\-[EQ] '='
+-[IDENT] 'status'
\-[COLON] ':'
\-[IDENT] 'oldstatus'


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 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.