-->
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.  [ 2 posts ] 
Author Message
 Post subject: Hibernate suppressing backslash char while saving object
PostPosted: Fri Apr 10, 2009 1:36 am 
Newbie

Joined: Fri Apr 10, 2009 1:21 am
Posts: 1
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:hibernate3

Mapping documents:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping package="curologic.test.example">
<class name="Stude" table="test" >
<id name="Identity" column="IDENTITY" type="java.lang.String"></id>
<property name="name" column="NAME" type="java.lang.String"></property>
</class>

</hibernate-mapping>



Code between sessionFactory.openSession() and session.close():
/**
* Returns the ThreadLocal Session instance. Lazy initialize the
* <code>SessionFactory</code> if needed.
*
* @return Session
* @throws HibernateException
*/
public Session openSession() {
return sessionFactory.getCurrentSession();
}

public static void close(){
if (sessionFactory != null)
sessionFactory.close();
sessionFactory = null;

}

Full stack trace of any exception that occurs:
No stack strace


Name and version of the database you are using:mysql5.0.22

The generated SQL (show_sql=true):
Hibernate: insert into test (NAME, IDENTITY) values (?, ?)
Hibernate: insert into test (NAME, IDENTITY) values (?, ?)



I have facing problem while saving object into database .i have given code below

import java.util.UUID;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;

public class TestExample
{

/**
* @param args
*/
public static void main(String[] args)
{
Transaction tx = null;
Session session = InitSessionFactory.getInstance().getCurrentSession();

String uuid = UUID.randomUUID().toString();
Stude stude = null;

stude = new Stude();
stude.setIdentity(uuid);
stude.setName("sha\\ad");

Stude stude1 = new Stude();
stude1.setIdentity(UUID.randomUUID().toString());
stude1.setName("abc\\\ad");
try
{
tx = session.beginTransaction();
session.save(stude);
session.save(stude1);

tx.commit();

}
catch (HibernateException e)
{
e.printStackTrace();
if (tx != null && tx.isActive()) tx.rollback();
}

}

}

for 1st record in database name should contain 'sha\\ad'
for 2nd record in database name should contain 'abc\\\ad'

Actually what happens hibernate suppress the backslash char in string.
But i want string that i was setting to stude object with slash char.



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


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 10, 2009 3:49 pm 
Regular
Regular

Joined: Mon Apr 19, 2004 6:54 pm
Posts: 79
"abc\\\ad" is not a valid java String

System.out.println("sha\\ad") --> sha\ad

if you want two \\:
System.out.println("sha\\\\ad") --> sha\\ad


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