-->
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.  [ 10 posts ] 
Author Message
 Post subject: Very strange problem
PostPosted: Wed May 04, 2005 11:30 am 
Beginner
Beginner

Joined: Thu Jan 13, 2005 10:31 am
Posts: 20
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 2.17

Mapping documents:

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

Full stack trace of any exception that occurs:

Name and version of the database you are using: Microsoft SQL Server 2000

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Hi,

My environment is Eclipse, Jboss 3.2.3 and MS SQL Server 2000 database. The Hibernate (hibernate.cfg.xml) is using a datasource which is using Microsoft SQL Server JDBC Driver.

I have a table wf_system_option_paaz

CREATE TABLE [dbo].[wf_system_option_paaz] (
[paazpk] smallint NOT NULL ,
[section_name] varchar(50) NULL ,
[keyword_value] varchar(50) NULL ,
[option_value] varchar(100) NULL
) ON [PRIMARY]

ALTER TABLE [dbo].[wf_system_option_paaz] WITH NOCHECK ADD
CONSTRAINT [XPKwf_system_option_paaz] PRIMARY KEY CLUSTERED
(
[paazpk]
) ON [PRIMARY]
GO


I have a screen (JSP) based on this table. User make changes to one row of the table and save them. The Update statement was :
update wf_system_option_paaz set section_name='TA', keyword_value='TSLOCKHOURS', option_value='0'
where paazpk='7'

Everything works ok.


Now I change hibernate.cfg.xml to use a datasource which is based on a ODBC connection and uses ODBC-JDBC Driver.

I perform the same operation; the update statement was same but in the table the varchar data now has been right padded upto its length with empty string. So for example the value of section_name column for this row is 'TA ' instead of 'TA'.



Any reason why this happening and how can I fix it? I have to support ODBC-JDBC Driver.



Thanks



2005-05-04 11:08:06,880 DEBUG [net.sf.hibernate.loader.Loader] total objects hydrated: 1
2005-05-04 11:08:06,880 DEBUG [net.sf.hibernate.impl.SessionImpl] resolving associations for [com.pendylum.main.model.SystemOption#7]
2005-05-04 11:08:06,880 DEBUG [net.sf.hibernate.impl.SessionImpl] done materializing entity [com.pendylum.main.model.SystemOption#7]
2005-05-04 11:08:06,880 DEBUG [net.sf.hibernate.impl.SessionImpl] initializing non-lazy collections
2005-05-04 11:08:06,880 INFO [STDOUT] ConfigurationManager.java: updateSystemOption(): aSystemOption.getOptionValue()[before]=0
2005-05-04 11:08:06,880 INFO [STDOUT] ConfigurationManager.java: updateSystemOption(): aSystemOption.getOptionValue()[after]=-5
2005-05-04 11:08:06,880 DEBUG [net.sf.hibernate.impl.SessionImpl] saveOrUpdate() persistent instance
2005-05-04 11:08:06,880 DEBUG [net.sf.hibernate.impl.SessionImpl] loading [com.pendylum.main.model.SystemOption#7]
2005-05-04 11:08:06,880 DEBUG [net.sf.hibernate.impl.SessionImpl] attempting to resolve [com.pendylum.main.model.SystemOption#7]
2005-05-04 11:08:06,880 DEBUG [net.sf.hibernate.impl.SessionImpl] resolved object in session cache [com.pendylum.main.model.SystemOption#7]
2005-05-04 11:08:06,880 INFO [STDOUT] ConfigurationManager.java: updateSystemOption(): bSystemOption.getOptionValue()[after save]=-5
2005-05-04 11:08:06,880 INFO [STDOUT] commitTransaction(): Committing database transaction of this thread (starting)
2005-05-04 11:08:06,880 INFO [STDOUT] commitTransaction(): Committing database transaction of this thread.
2005-05-04 11:08:06,880 DEBUG [net.sf.hibernate.transaction.JTATransaction] commit
2005-05-04 11:08:06,880 DEBUG [net.sf.hibernate.impl.SessionImpl] flushing session
2005-05-04 11:08:06,896 DEBUG [net.sf.hibernate.impl.SessionImpl] Flushing entities and processing referenced collections
2005-05-04 11:08:06,896 DEBUG [net.sf.hibernate.persister.AbstractEntityPersister] com.pendylum.main.model.SystemOption.optionValue is dirty
2005-05-04 11:08:06,896 DEBUG [net.sf.hibernate.impl.SessionImpl] Updating entity: [com.pendylum.main.model.SystemOption#7]
2005-05-04 11:08:06,896 DEBUG [net.sf.hibernate.impl.SessionImpl] Processing unreferenced collections
2005-05-04 11:08:06,896 DEBUG [net.sf.hibernate.impl.SessionImpl] Scheduling collection removes/(re)creates/updates
2005-05-04 11:08:06,896 DEBUG [net.sf.hibernate.impl.SessionImpl] Flushed: 0 insertions, 1 updates, 0 deletions to 1 objects
2005-05-04 11:08:06,896 DEBUG [net.sf.hibernate.impl.SessionImpl] Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
2005-05-04 11:08:06,896 DEBUG [net.sf.hibernate.impl.Printer] listing entities:
2005-05-04 11:08:06,896 DEBUG [net.sf.hibernate.impl.Printer] com.pendylum.main.model.SystemOption{systemOptionId=7, sectionName=TA, keywordValue=TSLOCKHOURS, optionValue=-5}
2005-05-04 11:08:06,896 DEBUG [net.sf.hibernate.impl.SessionImpl] executing flush
2005-05-04 11:08:06,896 DEBUG [net.sf.hibernate.persister.EntityPersister] Updating entity: [com.pendylum.main.model.SystemOption#7]
2005-05-04 11:08:06,896 DEBUG [net.sf.hibernate.impl.BatcherImpl] about to open: 0 open PreparedStatements, 0 open ResultSets
2005-05-04 11:08:06,896 DEBUG [net.sf.hibernate.SQL] update wf_system_option_paaz set section_name=?, keyword_value=?, option_value=? where paazpk=?
2005-05-04 11:08:06,896 DEBUG [net.sf.hibernate.impl.BatcherImpl] preparing statement
2005-05-04 11:08:06,896 DEBUG [net.sf.hibernate.persister.EntityPersister] Dehydrating entity: [com.pendylum.main.model.SystemOption#7]
2005-05-04 11:08:06,896 DEBUG [net.sf.hibernate.type.StringType] binding 'TA' to parameter: 1
2005-05-04 11:08:06,896 DEBUG [net.sf.hibernate.type.StringType] binding 'TSLOCKHOURS' to parameter: 2
2005-05-04 11:08:06,896 DEBUG [net.sf.hibernate.type.StringType] binding '-5' to parameter: 3
2005-05-04 11:08:06,896 DEBUG [net.sf.hibernate.type.ShortType] binding '7' to parameter: 4
2005-05-04 11:08:06,912 DEBUG [net.sf.hibernate.impl.BatcherImpl] done closing: 0 open PreparedStatements, 0 open ResultSets
2005-05-04 11:08:06,912 DEBUG [net.sf.hibernate.impl.BatcherImpl] closing statement
2005-05-04 11:08:06,912 DEBUG [net.sf.hibernate.impl.SessionImpl] post flush
2005-05-04 11:08:06,912 INFO [STDOUT] HibernateHelper: commitTransaction() successfully executed.
2005-05-04 11:08:06,912 INFO [STDOUT] HibernateHelper: Closing Session of this thread.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 04, 2005 1:05 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
your bridge implementation is buggy.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 04, 2005 1:15 pm 
Beginner
Beginner

Joined: Thu Jan 13, 2005 10:31 am
Posts: 20
Quote:
your bridge implementation is buggy.


i am a new user and could not understand the above statement at all. Please explain it.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 04, 2005 1:18 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
your jdbc-odbc bridge has a bug. There is nothing much you can do about that.
This is a pitty you can't switch, but jTds is a very good free triver (better than the MS one)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 04, 2005 7:47 pm 
Beginner
Beginner

Joined: Thu Jan 13, 2005 10:31 am
Posts: 20
Quote:
your jdbc-odbc bridge has a bug


I performed a test. I wrote code which does not use hibernate. It connects to database through the same ODBC connection (using jdbc-odbc bridge) using DriverManager and executes the same update statement. It works perfect.

Can you explain this behaviour?


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 04, 2005 8:39 pm 
Beginner
Beginner

Joined: Thu Jan 13, 2005 10:31 am
Posts: 20
This is the test code:


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class TestUpdate {

public static void main(String[] args) {

Connection connection = null;
Statement stmt = null;

// Get ODBC Connection
String driverName = "sun.jdbc.odbc.JdbcOdbcDriver";
String databaseUrl = "jdbc:odbc:webflex1";
String userId = "sa";
String password = "wf";

try {
Class.forName(driverName);
connection = DriverManager.getConnection(databaseUrl, userId, password);
} catch (ClassNotFoundException cnfe) {
System.out.println("cnfe.getMessage()= " + cnfe.getMessage());
cnfe.printStackTrace();
} catch (SQLException sqle) {
System.out.println("sqle.getMessage()= " + sqle.getMessage());
sqle.printStackTrace();
}

try {
String updateStatement = "update wf_system_option_paaz set section_name='TA', keyword_value='TSLOCKHOURS', option_value='-5' where paazpk='7'";

stmt = connection.createStatement();

stmt.executeUpdate( updateStatement );

} catch (SQLException e) {
System.out.println("CreateStatement Error");
e.printStackTrace();
} finally {
if ( stmt != null ) {
try {
stmt.close();
} catch (SQLException e1) {
System.out.println("Statement Close Error");
e1.printStackTrace();
}
}

if ( connection != null ) {
try {
connection.close();
} catch (SQLException e) {
System.out.println("Connection Close Error");
e.printStackTrace();
}
}

}


}
}


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 05, 2005 5:17 am 
jTDS Developer
jTDS Developer

Joined: Tue Feb 24, 2004 5:36 pm
Posts: 70
Location: Bucharest, Romania
Your test code definitely does not execute the same statement as Hibernate. Hibernate always uses PreparedStatements whereas you used a plain statement; if you use a PreparedStatement too you'll probably find out that the extra blank is appended to the value. This is definitely a bug with the driver (either the JDBC-ODBC bridge or the ODBC driver).

Alin,
The jTDS Project.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 05, 2005 11:10 am 
Beginner
Beginner

Joined: Thu Jan 13, 2005 10:31 am
Posts: 20
You are right. I performed the test with PreparedStatement and it append the extra blanks to the value.

In the ODBC connection there is a property "Use ANSI nulls, paddings, and warnings". For my ODBC connection it was checked. I unchecked it and test and it works with PreparedStatement and so with Hibernate.

My question is what i will miss if i keep this property unchecked?


Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 05, 2005 12:37 pm 
jTDS Developer
jTDS Developer

Joined: Tue Feb 24, 2004 5:36 pm
Posts: 70
Location: Bucharest, Romania
Take a look at this [microsoft.com].

Alin.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 10, 2005 5:16 pm 
Beginner
Beginner

Joined: Thu Jan 13, 2005 10:31 am
Posts: 20
Quote:
Take a look at this [microsoft.com].


According to this i cannot afford to uncheck the "Use ANSI nulls, paddings, and warnings" property of my ODBC connection. It means I have to go with a JDBC Driver.

Now I have an 'Hejb' which is using Hibernate (Local Session Pattern) and uses MS SQL Server JDBC Driver [mssql-ds.xml]. There is another EJB 'NHejb' which is not using Hibernate and uses the JDBC-ODBC driver [odbc-ds.xml]. Now when I test my stuff everything works ok.

In one of my screen, I call a method in 'Hejb' which calls a method in the 'NHejb' to perform some work. It works ok but in the log file I am getting this message twice:

WARN [TxConnectionManager] Prepare called on a local tx. Use of local transactions on a jta transaction with more than one branch may result in inconsistent data in some cases of failure.

What is this warning means and how can i remove it?

I installed my application on another PC and now ocassionally on that screen I got an error message in my log file :

Connection handle is not currently associated with a ManagedConnection.

Can this error be fixed?

Thanks


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