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