Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java Open Source > BOOK: Professional Hibernate
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional Hibernate
This is the forum to discuss the Wrox book Professional Hibernate by Eric Pugh, Joseph D. Gradecki; ISBN: 9780764576775
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional Hibernate section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old March 29th, 2005, 10:39 AM
Registered User
 
Join Date: Mar 2005
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Book Example NOT working with SQL SERVER

I started the CDTest example (the swing component) from the command line like so :
java -classpath .;C:\Hibernate\hibernate2.jar;C:\Hibernate\lib\dom 4j-1.4.jar;C:\Hibernate\lib\commons-logging-1.0.4.jar;C:\Hibernate\lib\commons-collections-2.1.1.jar;C:\SQLServerJDBC\lib\msbase.jar;C:\SQLSe rverJDBC\lib\mssqlserver.jar;C:\SQLServerJDBC\lib\ msutil.jar;C:\Hibernate\lib\ehcache-0.9.jar;C:\Hibernate\lib\cglib-full-2.0.2.jar;C:\Sun\AppServer\lib\j2ee.jar CDTest

(Please note that I had to include that I have to include everything when calling from the commandline (even though when I echo %CLASSPATH% the above is present.

When I start the application and then try to add something to the SQL Server products database's CD table. I get the following error regarding the ID primary key which is an int:


Hibernate: insert into cd (title, artist, purchasedate, cost, ID) values (?, ?,
?, ?, ?)
Mar 28, 2005 10:34:02 AM net.sf.hibernate.util.JDBCExceptionReporter logExceptio
ns
WARNING: SQL Error: 245, SQLState: 22018
Mar 28, 2005 10:34:02 AM net.sf.hibernate.util.JDBCExceptionReporter logExceptio
ns
SEVERE: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Syntax error conve
rting the nvarchar value '#9492;¿#9787;#9829;éiK~?éiL#9568;#9786;Ç?' to a column of data type int.
Mar 28, 2005 10:34:02 AM net.sf.hibernate.impl.SessionImpl execute
SEVERE: Could not synchronize database state with session
net.sf.hibernate.exception.GenericJDBCException: could not insert: [CD##9492;¿#9787;#9829;éiK~?
éiL#9568;#9786;Ç?]
        at net.sf.hibernate.exception.SQLStateConverter.handl edNonSpecificExcept
ion(SQLStateConverter.java:80)
        at net.sf.hibernate.exception.SQLStateConverter.conve rt(SQLStateConverte
r.java:69)
        at net.sf.hibernate.exception.JDBCExceptionHelper.con vert(JDBCExceptionH
elper.java:29)
        at net.sf.hibernate.persister.AbstractEntityPersister .convert(AbstractEn
tityPersister.java:1331)
        at net.sf.hibernate.persister.EntityPersister.insert( EntityPersister.jav
a:472)
        at net.sf.hibernate.persister.EntityPersister.insert( EntityPersister.jav
a:436)
        at net.sf.hibernate.impl.ScheduledInsertion.execute(S cheduledInsertion.j
ava:37)
        at net.sf.hibernate.impl.SessionImpl.execute(SessionI mpl.java:2449)
        at net.sf.hibernate.impl.SessionImpl.executeAll(Sessi onImpl.java:2435)
        at net.sf.hibernate.impl.SessionImpl.execute(SessionI mpl.java:2392)
        at net.sf.hibernate.impl.SessionImpl.flush(SessionImp l.java:2261)
        at CDTest$3.actionPerformed(CDTest.java:113)
        at javax.swing.AbstractButton.fireActionPerformed(Unk nown Source)
        at javax.swing.AbstractButton$ForwardActionEvents.act ionPerformed(Unknow
n Source)
        at javax.swing.DefaultButtonModel.fireActionPerformed (Unknown Source)
        at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
        at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(Unknown Sour
ce)
        at java.awt.Component.processMouseEvent(Unknown Source)
        at java.awt.Component.processEvent(Unknown Source)
        at java.awt.Container.processEvent(Unknown Source)
        at java.awt.Component.dispatchEventImpl(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.LightweightDispatcher.retargetMouseEvent( Unknown Source)
        at java.awt.LightweightDispatcher.processMouseEvent(U nknown Source)
        at java.awt.LightweightDispatcher.dispatchEvent(Unkno wn Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Window.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForHierar chy(Unknown Source)

        at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQ
LServer]Syntax error converting the nvarchar value '#9492;¿#9787;#9829;éiK~?éiL#9568;#9786;Ç?' to a colum
n of data type int.
        at com.microsoft.jdbc.base.BaseExceptions.createExcep tion(Unknown Source
)
        at com.microsoft.jdbc.base.BaseExceptions.getExceptio n(Unknown Source)
        at com.microsoft.jdbc.sqlserver.tds.TDSRequest.proces sErrorToken(Unknown
 Source)
        at com.microsoft.jdbc.sqlserver.tds.TDSRequest.proces sReplyToken(Unknown
 Source)
        at com.microsoft.jdbc.sqlserver.tds.TDSRPCRequest.pro cessReplyToken(Unkn
own Source)
        at com.microsoft.jdbc.sqlserver.tds.TDSRequest.proces sReply(Unknown Sour
ce)
        at com.microsoft.jdbc.sqlserver.SQLServerImplStatemen t.getNextResultType
(Unknown Source)
        at com.microsoft.jdbc.base.BaseStatement.commonTransi tionToState(Unknown
 Source)
        at com.microsoft.jdbc.base.BaseStatement.postImplExec ute(Unknown Source)

        at com.microsoft.jdbc.base.BasePreparedStatement.post ImplExecute(Unknown
 Source)
        at com.microsoft.jdbc.base.BaseStatement.commonExecut e(Unknown Source)
        at com.microsoft.jdbc.base.BaseStatement.executeUpdat eInternal(Unknown S
ource)
        at com.microsoft.jdbc.base.BasePreparedStatement.exec uteUpdate(Unknown S
ource)
        at net.sf.hibernate.impl.NonBatchingBatcher.addToBatc h(NonBatchingBatche
r.java:22)
        at net.sf.hibernate.persister.EntityPersister.insert( EntityPersister.jav
a:462)
        ... 30 more
Mar 28, 2005 10:34:02 AM net.sf.hibernate.impl.SessionImpl finalize
WARNING: unclosed connection, forgot to call close() on your session?


So I went ahead and changed the ID primary key to numeric with the same error :

Hibernate: insert into cd (title, artist, purchasedate, cost, ID) values (?, ?,
?, ?, ?)
Mar 28, 2005 10:18:17 AM net.sf.hibernate.util.JDBCExceptionReporter logExceptio
ns
WARNING: SQL Error: 8114, SQLState: HY000
Mar 28, 2005 10:18:17 AM net.sf.hibernate.util.JDBCExceptionReporter logExceptio
ns
SEVERE: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Error converting d
ata type nvarchar to numeric.
Mar 28, 2005 10:18:17 AM net.sf.hibernate.impl.SessionImpl execute
SEVERE: Could not synchronize database state with session
net.sf.hibernate.exception.GenericJDBCException: could not insert: [CD##9492;¿#9787;#9829;éi=)?
éi=_PÇ?]
        at net.sf.hibernate.exception.SQLStateConverter.handl edNonSpecificExcept
ion(SQLStateConverter.java:80)
        at net.sf.hibernate.exception.SQLStateConverter.conve rt(SQLStateConverte
r.java:69)
        at net.sf.hibernate.exception.JDBCExceptionHelper.con vert(JDBCExceptionH
elper.java:29)
        at net.sf.hibernate.persister.AbstractEntityPersister .convert(AbstractEn
tityPersister.java:1331)
        at net.sf.hibernate.persister.EntityPersister.insert( EntityPersister.jav
a:472)
        at net.sf.hibernate.persister.EntityPersister.insert( EntityPersister.jav
a:436)
        at net.sf.hibernate.impl.ScheduledInsertion.execute(S cheduledInsertion.j
ava:37)
        at net.sf.hibernate.impl.SessionImpl.execute(SessionI mpl.java:2449)
        at net.sf.hibernate.impl.SessionImpl.executeAll(Sessi onImpl.java:2435)
        at net.sf.hibernate.impl.SessionImpl.execute(SessionI mpl.java:2392)
        at net.sf.hibernate.impl.SessionImpl.flush(SessionImp l.java:2261)
        at CDTest$3.actionPerformed(CDTest.java:113)
        at javax.swing.AbstractButton.fireActionPerformed(Unk nown Source)
        at javax.swing.AbstractButton$ForwardActionEvents.act ionPerformed(Unknow
n Source)
        at javax.swing.DefaultButtonModel.fireActionPerformed (Unknown Source)
        at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
        at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(Unknown Sour
ce)
        at java.awt.Component.processMouseEvent(Unknown Source)
        at java.awt.Component.processEvent(Unknown Source)
        at java.awt.Container.processEvent(Unknown Source)
        at java.awt.Component.dispatchEventImpl(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.LightweightDispatcher.retargetMouseEvent( Unknown Source)
        at java.awt.LightweightDispatcher.processMouseEvent(U nknown Source)
        at java.awt.LightweightDispatcher.dispatchEvent(Unkno wn Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Window.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForHierar chy(Unknown Source)

        at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQ
LServer]Error converting data type nvarchar to numeric.
        at com.microsoft.jdbc.base.BaseExceptions.createExcep tion(Unknown Source
)
        at com.microsoft.jdbc.base.BaseExceptions.getExceptio n(Unknown Source)
        at com.microsoft.jdbc.sqlserver.tds.TDSRequest.proces sErrorToken(Unknown
 Source)
        at com.microsoft.jdbc.sqlserver.tds.TDSRequest.proces sReplyToken(Unknown
 Source)
        at com.microsoft.jdbc.sqlserver.tds.TDSRPCRequest.pro cessReplyToken(Unkn
own Source)
        at com.microsoft.jdbc.sqlserver.tds.TDSRequest.proces sReply(Unknown Sour
ce)
        at com.microsoft.jdbc.sqlserver.SQLServerImplStatemen t.getNextResultType
(Unknown Source)
        at com.microsoft.jdbc.base.BaseStatement.commonTransi tionToState(Unknown
 Source)
        at com.microsoft.jdbc.base.BaseStatement.postImplExec ute(Unknown Source)

        at com.microsoft.jdbc.base.BasePreparedStatement.post ImplExecute(Unknown
 Source)
        at com.microsoft.jdbc.base.BaseStatement.commonExecut e(Unknown Source)
        at com.microsoft.jdbc.base.BaseStatement.executeUpdat eInternal(Unknown S
ource)
        at com.microsoft.jdbc.base.BasePreparedStatement.exec uteUpdate(Unknown S
ource)
        at net.sf.hibernate.impl.NonBatchingBatcher.addToBatc h(NonBatchingBatche
r.java:22)
        at net.sf.hibernate.persister.EntityPersister.insert( EntityPersister.jav
a:462)
        ... 30 more


So I went ahead and changed the ID primary key into a nvarchar and this time the application froze Enterprise Manager. I was UNABLE to open any of the tables because there was a sharing violation error and then when I had shut down the console window (or the command line window that I used to start CDTest), I looked into the database and it was neither updated nor inserted into :


Hibernate: insert into cd (title, artist, purchasedate, cost, ID) values (?, ?,
?, ?, ?)
Mar 28, 2005 10:19:48 AM net.sf.hibernate.util.JDBCExceptionReporter logWarnings

WARNING: SQL Warning: 0, SQLState:
Mar 28, 2005 10:19:48 AM net.sf.hibernate.util.JDBCExceptionReporter logWarnings

WARNING: [Microsoft][SQLServer 2000 Driver for JDBC]Database changed to products

Mar 28, 2005 10:19:48 AM net.sf.hibernate.util.JDBCExceptionReporter logWarnings

WARNING: SQL Warning: 0, SQLState:
Mar 28, 2005 10:19:48 AM net.sf.hibernate.util.JDBCExceptionReporter logWarnings

WARNING: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Changed database
context to 'products'.
Mar 28, 2005 10:19:48 AM net.sf.hibernate.util.JDBCExceptionReporter logWarnings

WARNING: SQL Warning: 0, SQLState:
Mar 28, 2005 10:19:48 AM net.sf.hibernate.util.JDBCExceptionReporter logWarnings

WARNING: [Microsoft][SQLServer 2000 Driver for JDBC]Language changed to us_engli
sh
Mar 28, 2005 10:19:48 AM net.sf.hibernate.util.JDBCExceptionReporter logWarnings

WARNING: SQL Warning: 0, SQLState:
Mar 28, 2005 10:19:48 AM net.sf.hibernate.util.JDBCExceptionReporter logWarnings

WARNING: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Changed language
setting to us_english.


Following is the setting and the part that prints to console before the error :

Mar 28, 2005 10:19:09 AM net.sf.hibernate.cfg.Environment <clinit>
INFO: Hibernate 2.1.8
Mar 28, 2005 10:19:09 AM net.sf.hibernate.cfg.Environment <clinit>
INFO: loaded properties from resource hibernate.properties: {hibernate.connectio
n.username=sa , hibernate.connection.password=sa, hibernate.cglib.use_reflection
_optimizer=true, hibernate.dialect=net.sf.hibernate.dialect.SQLServ erDialect, hi
bernate.show_sql=true, hibernate.connection.url=jdbc:microsoft:sqlserver://local
host:1433;databaseName=products;selectMethod=curso r;, hibernate.connection.drive
r_class=com.microsoft.jdbc.sqlserver.SQLServerDriv er}
Mar 28, 2005 10:19:09 AM net.sf.hibernate.cfg.Environment <clinit>
INFO: using CGLIB reflection optimizer
Mar 28, 2005 10:19:09 AM net.sf.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
Mar 28, 2005 10:19:09 AM net.sf.hibernate.cfg.Configuration addClass
INFO: Mapping resource: CD.hbm.xml
Mar 28, 2005 10:19:09 AM net.sf.hibernate.cfg.Binder bindRootClass
INFO: Mapping class: CD -> cd
Mar 28, 2005 10:19:09 AM net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing one-to-many association mappings
Mar 28, 2005 10:19:09 AM net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing one-to-one association property references
Mar 28, 2005 10:19:09 AM net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing foreign key constraints
Mar 28, 2005 10:19:09 AM net.sf.hibernate.dialect.Dialect <init>
INFO: Using dialect: net.sf.hibernate.dialect.SQLServerDialect
Mar 28, 2005 10:19:09 AM net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Use outer join fetching: true
Mar 28, 2005 10:19:10 AM net.sf.hibernate.connection.DriverManagerConnectio nProv
ider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
Mar 28, 2005 10:19:10 AM net.sf.hibernate.connection.DriverManagerConnectio nProv
ider configure
INFO: Hibernate connection pool size: 20
Mar 28, 2005 10:19:10 AM net.sf.hibernate.connection.DriverManagerConnectio nProv
ider configure
INFO: using driver: com.microsoft.jdbc.sqlserver.SQLServerDriver at URL: jdbc:mi
crosoft:sqlserver://localhost:1433;databaseName=products;selectMethod= cursor;
Mar 28, 2005 10:19:10 AM net.sf.hibernate.connection.DriverManagerConnectio nProv
ider configure
INFO: connection properties: {user=test , password=test}
Mar 28, 2005 10:19:10 AM net.sf.hibernate.transaction.TransactionManagerLoo kupFa
ctory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of process
 level read-write cache is not recommended)
Mar 28, 2005 10:19:10 AM net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Use scrollable result sets: true
Mar 28, 2005 10:19:10 AM net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Use JDBC3 getGeneratedKeys(): false
Mar 28, 2005 10:19:10 AM net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: false
Mar 28, 2005 10:19:10 AM net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: echoing all SQL to stdout
Mar 28, 2005 10:19:10 AM net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
Mar 28, 2005 10:19:10 AM net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: cache provider: net.sf.hibernate.cache.EhCacheProvider
Mar 28, 2005 10:19:10 AM net.sf.hibernate.cfg.Configuration configureCaches
INFO: instantiating and configuring caches
Mar 28, 2005 10:19:10 AM net.sf.ehcache.config.Configurator configure
WARNING: No configuration found. Configuring ehcache from ehcache-failsafe.xml f
ound in the classpath: jar:file:/C:/Hibernate/lib/ehcache-0.9.jar!/ehcache-fails
afe.xml
Mar 28, 2005 10:19:10 AM net.sf.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
Mar 28, 2005 10:19:10 AM net.sf.hibernate.impl.SessionFactoryObjectFactory addIn
stance
INFO: Not binding factory to JNDI, no JNDI name configured

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL In book not working bgcsocal SQL Server 2005 3 August 5th, 2008 12:54 PM
Help required with VB SQL Server 7.0 Book.. danfeather SQL Server 2000 1 September 29th, 2005 08:47 PM
working with money values in sql server mattastic SQL Server 2000 3 September 29th, 2005 08:15 PM
How Can SQL Server working with ASP??? aliasp SQL Server ASP 1 March 18th, 2004 02:13 PM
SQL Server Book psingh SQL Server 2000 1 June 13th, 2003 02:33 PM



All times are GMT -4. The time now is 12:38 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.