-->
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.  [ 4 posts ] 
Author Message
 Post subject: issue saving user object to the database with uniqueid.
PostPosted: Mon Jun 30, 2008 12:57 pm 
Newbie

Joined: Fri Jan 26, 2007 10:37 am
Posts: 6
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.2.6ga

Mapping documents:

<class name="com.colorful.earthbeats.beans.User" table="users">

<id name="userid" type="long" column="userid" >
<generator class="native" />
</id>
...

<!-- encrypt the password for inserts updates. -->
<sql-insert>INSERT INTO users (userid, ..., password,...) values (?, ?, AES_ENCRYPT(?,'&key;'),...);</sql-insert>
<sql-update>UPDATE ... where userid = ?;</sql-update>

</class>
NOTE: The order of the parameters here matches the order given by the generated hibernate debug output.


Code between sessionFactory.openSession() and session.close():

sessionFactory.getCurrentSession().saveOrUpdate(user);



Full stack trace of any exception that occurs:

%org.hibernate.exception.GenericJDBCException: could not insert: [com.colorful.earthbeats.
beans.User]
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateC
onverter.java:103)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43
)
at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturni
ngDelegate.java:40)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPer
sister.java:2163)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPer
sister.java:2643)
at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAct
ion.java:51)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(Abstra
ctSaveEventListener.java:298)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEvent
Listener.java:181)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractS
aveEventListener.java:107)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrReq
uestedId(DefaultSaveOrUpdateEventListener.java:187)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(Defa
ultSaveOrUpdateEventListener.java:172)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(De
faultSaveOrUpdateEventListener.java:94)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(Default
SaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:507)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:499)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:495)
at com.colorful.earthbeats.dao.UserDAO.persistUser(UserDAO.java:68)
at com.colorful.earthbeats.dao.UserDAO$$FastClassByCGLIB$$bdacca17.invoke(<generat
ed>)
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJo
inpoint(Cglib2AopProxy.java:693)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(Reflective
MethodInvocation.java:139)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(Trans
actionInterceptor.java:107)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(Reflective
MethodInvocation.java:161)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.inte
rcept(Cglib2AopProxy.java:628)
at com.colorful.earthbeats.dao.UserDAO$$EnhancerByCGLIB$$8db0cdbb.persistUser(<gen
erated>)
at com.colorful.earthbeats.servlet.RegisterConfirmServlet.doPost(RegisterConfirmSe
rvlet.java:133)
at com.colorful.earthbeats.servlet.RegisterConfirmServlet.doGet(RegisterConfirmSer
vlet.java:40)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:693)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFil
terChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain
.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:
233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:
175)
at org.apache.geronimo.tomcat.valve.DefaultSubjectValve.invoke(DefaultSubjectValve
.java:51)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.ja
va:433)
at org.apache.geronimo.tomcat.GeronimoStandardContext$SystemMethodValve.invoke(Ger
onimoStandardContext.java:396)
at org.apache.geronimo.tomcat.valve.GeronimoBeforeAfterValve.invoke(GeronimoBefore
AfterValve.java:47)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:10
9)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:563)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:190)
at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:283)
at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:767)
at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:697)
at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:88
9)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:6
90)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.sql.SQLException: Statement parameter 15 not set.
at com.mysql.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedStatement.ja
va:1031)
at com.mysql.jdbc.ServerPreparedStatement.executeInternal(ServerPreparedStatement.
java:676)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1166)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1082)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1067)
at org.tranql.connector.jdbc.PreparedStatementHandle.executeUpdate(PreparedStateme
ntHandle.java:103)
at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(I
dentityGenerator.java:73)
at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturni
ngDelegate.java:33)
... 47 more


Name and version of the database you are using:

MySql 5 on linux amd 64

The generated SQL (show_sql=true):
10:57:36,318 DEBUG [AbstractEntityPersister] Snapshot select: select user_.userid, user_.
email as email5_, user_.name as name5_, user_.payPalEmail as payPalEm4_5_, user_.password
as password5_, user_.regType as regType5_, user_.about as about5_, user_.city as city5_, u
ser_.state as state5_, user_.country as country5_, user_.fanWeb as fanWeb5_, user_.fanEmai
l as fanEmail5_, user_.allowsEmail as allowsE13_5_, user_.dateAdded as dateAdded5_, user_.
dateModified as dateMod15_5_ from users user_ where user_.userid=?
10:57:36,319 DEBUG [AbstractEntityPersister] Insert 0: INSERT INTO users (userid, payPalE
mail, password, regType, about, city, state, country, fanWeb, fanEmail, allowsEmail, dateA
dded, dateModified, email, name) values (?, ?, AES_ENCRYPT(?,'SecretKey'), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);
10:57:36,320 DEBUG [AbstractEntityPersister] Update 0: UPDATE users set email=?, name=?,
payPalEmail=?, password=AES_ENCRYPT(?,'SecretKey'), regType=?
, about=?, city=?, state=?, country=?, fanWeb=?, fanEmail=?, allowsEmail=?, dateAdded=?, d
ateModified=? where userid = ?;
10:57:36,320 DEBUG [AbstractEntityPersister] Delete 0: delete from users where userid=?
10:57:36,321 DEBUG [AbstractEntityPersister] Identity insert: INSERT INTO users (userid,
payPalEmail, password, regType, about, city, state, country, fanWeb, fanEmail, allowsEmail
, dateAdded, dateModified, email, name) values (?, ?, AES_ENCRYPT(?,'SecretKey'), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);



Debug level Hibernate log excerpt:


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html

Greetings:

I recently needed to change the primary key in my user table from a String to a unique auto increment long value. This value is the primary key. Since then, I have been unable to save a new item into the database. My User class defines the following unique id and contains the getter and setters.

public calss User implements Serializable {
...
private long userid = 0; //unique id for the user.
public long getUserid(){
return userid;
}
public void setUserid(long userid){
this.userid = userid;
}
...
}

Can anyone on this forum determine why I might be getting the exception above?

Any insight is appreciated.

Thanks.
Bill.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 30, 2008 4:56 pm 
Newbie

Joined: Fri Jan 26, 2007 10:37 am
Posts: 6
Greetings:

I was able to get some more debug out put and see that the binding order of the parameters does not match the order specified by the generated Hibernate static insert above.

30 Jun 2008 13:27:00,393 TRACE [GeronimoLog.trace() (line:54)] - Inserting entity: com.co
lorful.earthbeats.beans.User (native id)
30 Jun 2008 13:27:00,400 DEBUG [GeronimoLog.debug() (line:66)] -
INSERT
INTO
users
(userid, payPalEmail, password, regType, about, city, state, country, fanWeb, fanE
mail, allowsEmail, dateAdded, dateModified, email, name)
values
(?, ?, AES_ENCRYPT(?,'secretKey'), ?, ?, ?, ?, ?, ?,
?, ?, ?, ?, ?, ?);
30 Jun 2008 13:27:00,409 TRACE [GeronimoLog.trace() (line:54)] - Dehydrating entity: [com
.colorful.earthbeats.beans.User#<null>]
30 Jun 2008 13:27:00,410 TRACE [GeronimoLog.trace() (line:54)] - binding 'some@email.com' to parameter: 1
30 Jun 2008 13:27:00,411 TRACE [GeronimoLog.trace() (line:54)] - binding 'Anonymous' to parameter: 2
30 Jun 2008 13:27:00,412 TRACE [GeronimoLog.trace() (line:54)] - binding null to parameter: 3
30 Jun 2008 13:27:00,413 TRACE [GeronimoLog.trace() (line:54)] - binding 'aPassword' to parameter: 4
30 Jun 2008 13:27:00,414 TRACE [GeronimoLog.trace() (line:54)] - binding 'listener' to parameter: 5
30 Jun 2008 13:27:00,415 TRACE [GeronimoLog.trace() (line:54)] - binding null to parameter: 6
30 Jun 2008 13:27:00,415 TRACE [GeronimoLog.trace() (line:54)] - binding null to parameter: 7
30 Jun 2008 13:27:00,416 TRACE [GeronimoLog.trace() (line:54)] - binding null to parameter: 8
30 Jun 2008 13:27:00,417 TRACE [GeronimoLog.trace() (line:54)] - binding null to parameter: 9
30 Jun 2008 13:27:00,418 TRACE [GeronimoLog.trace() (line:54)] - binding null to parameter: 10
30 Jun 2008 13:27:00,419 TRACE [GeronimoLog.trace() (line:54)] - binding null to parameter: 11
30 Jun 2008 13:27:00,419 TRACE [GeronimoLog.trace() (line:54)] - binding 'false' to parameter: 12
30 Jun 2008 13:27:00,421 TRACE [GeronimoLog.trace() (line:54)] - binding '2008-06-30 13:27:00' to parameter: 13
30 Jun 2008 13:27:00,422 TRACE [GeronimoLog.trace() (line:54)] - binding '2008-06-30 13:27:00' to parameter: 14
30 Jun 2008 13:27:00,447 ERROR [RegisterConfirmServlet.doPost() (line:154)] - error confirming registration

It looks like the email is being bound to parameter 1 which I thought should be the userid (unique key) generated from mysql static statement above.

Does this provide any more information for the troubleshooting experts?

Thanks.
Bill.


Top
 Profile  
 
 Post subject: SOLVED: issue saving user object to database with uniqueid
PostPosted: Mon Jun 30, 2008 9:58 pm 
Newbie

Joined: Fri Jan 26, 2007 10:37 am
Posts: 6
Greetings:

I found that adding the unique id field to my table changed the order of the default static insert and update statements. I was able to resolve the issue by temporarily commenting out the custom insert and update in my class mapping:

<!-- encrypt the password for inserts updates.
<sql-insert>INSERT INTO users (userid, ..., password,...) values (?, ?, AES_ENCRYPT(?,'&key;'),...);</sql-insert>
<sql-update>UPDATE ... where userid = ?;</sql-update>
-->

This caused the debug output to show the correct order of the fields. I then changed the abouve custom insert and update to match the order rendered by the default static insert and delete.

HTH others who run into this type of issue.

Thanks.
Bill.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 04, 2008 10:56 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Awesome! Thanks for the update.

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


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