-->
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.  [ 5 posts ] 
Author Message
 Post subject: Can not insert special chracter using Hibernate
PostPosted: Tue Jun 07, 2011 5:50 am 
Newbie

Joined: Mon Jun 06, 2011 2:44 am
Posts: 4
Hi,
In my application, I am using Hibernate 3 and MySQL 5.1.
I try to insert name in data base using Session.save(object) and it works fine, untill, when I use Chracter ['] in the name, like D'souza.
It gives JDBC exception and insertion fail.
I found the root cause of the exception, Hibernate internally creates SQL insert statement, like,
INSERT INTO table_name (name) VALUES ('D'souza');
If we tried this example in MySQL, it also give exception, actually it is confused regarding the Character symbol.

Is there any possible solution??


Top
 Profile  
 
 Post subject: Re: Can not insert special chracter using Hibernate
PostPosted: Tue Jun 14, 2011 2:30 am 
Newbie

Joined: Mon Jun 06, 2011 2:44 am
Posts: 4
Hi team, please help me, I can't find any solution......


Top
 Profile  
 
 Post subject: Re: Can not insert special chracter using Hibernate
PostPosted: Tue Jun 14, 2011 2:56 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Hibernate shouldn't have this problem. Insert queries are generated with parameter placeholders. Eg.

Code:
INSERT INTO table_name (name) VALUES (?)


You'll need to post more information if you want help. Mappings files, code, log output, etc.


Top
 Profile  
 
 Post subject: Re: Can not insert special chracter using Hibernate
PostPosted: Tue Jun 14, 2011 5:02 am 
Newbie

Joined: Mon Jun 06, 2011 2:44 am
Posts: 4
Hi Nordborg,
Thank you for suggested reply.
What you said, I agree and I mention same in my post also.

Here is my Mappings file,

<class name="Patientname" table="patientname">
<id name="ehrid" column="ehrid" type="java.lang.String" >
</id>
<property name="firstname" column="firstname" type="java.lang.String"></property>
<property name="lastName" column="lastName" type="java.lang.String"></property>
<property name="middlename" column="middlename" type="java.lang.String"></property>
</class>

Here is my code,

patientname.setEhrid(uuid.toString());
patientname.setFirstname(pName.getFirstName());
patientname.setLastName(pName.getLastName());
patientname.setMiddlename(pName.getMiddleName());
session.save(patientname);
session.flush();
session.clear();

Here is log output,

at java.lang.Thread.run(Thread.java:662)
Caused by: org.hibernate.TransactionException: Transaction not successfully started
at org.hibernate.transaction.JDBCTransaction.rollback(JDBCTransaction.java:149)

Now please suggest me some improvement


Top
 Profile  
 
 Post subject: Re: Can not insert special chracter using Hibernate
PostPosted: Tue Jun 14, 2011 5:11 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
That's is not the log output. Please enable Hibernate logging and make sure that the SQL statements Hibernate generates are included (http://docs.jboss.org/hibernate/core/3. ... on-logging). This will usually generate a huge log file, so it would be good if you could find and post the relevant parts.


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