-->
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.  [ 1 post ] 
Author Message
 Post subject: Hibernate 3.2: Oracle Clob management and deadlock
PostPosted: Tue May 29, 2007 4:10 am 
Newbie

Joined: Mon Apr 16, 2007 12:02 pm
Posts: 17
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.2

Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
'-//Hibernate/Hibernate Mapping DTD 3.0//EN'
'http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd'>
<hibernate-mapping package="com.toluna.samuel.hibernate.emailtemplate">
<class name="EmailTemplate" table="EmailTemplate">

<id name="id" type="long">
<column name="template_id" not-null="true"/>
<generator class="native"/>
</id>

<property name="name">
<column name="email_name" not-null="false"/>
</property>


<property name="htmlTextClob" type="clob">
<column name="html_Text" not-null="false"/>
</property>

<property name="plainTextClob" type="clob">
<column name="plain_Text" not-null="false"/>
</property>
</class>
</hibernate-mapping>

Extract also of my Java bean:
ublic class EmailTemplate {

private long id;
private String name;
private String plainText = " ";
private String htmlText = " ";
private Clob plainTextClob;
private Clob htmlTextClob;
...

Code between sessionFactory.openSession() and session.close():
Session ss = HibernateUtil.getSessionFactory().getCurrentSession();
//S_LOGGER.debug("Number of current Hibernate sessions: "+ HibernateUtil.getSessionFactory().getStatistics().getSessionOpenCount());

ss.getTransaction().begin();

EmailTemplate et = (EmailTemplate) ss.load(EmailTemplate.class, new Long("299941536982302"));
S_LOGGER.debug(et.getName());

Thread.sleep(5000);
S_LOGGER.debug("BEFORE FLUSH");
ss.flush();
S_LOGGER.debug("AFTER FLUSH");

ss.getTransaction().commit();
Full stack trace of any exception that occurs:
N/A
Name and version of the database you are using:
Oracle 10g v2
The generated SQL (show_sql=true):

The load statement is always generated:
/* load com.toluna.samuel.hibernate.emailtemplate.EmailTemplate */ select
emailtempl0_.template_id as template1_0_0_,
emailtempl0_.email_name as email2_0_0_,
emailtempl0_.html_Text as html3_0_0_,
emailtempl0_.plain_Text as plain4_0_0_
from
EmailTemplate emailtempl0_
where
emailtempl0_.template_id=?
....

Depending on the implementation of the getter, the following update statement is generated:

/* update
com.toluna.samuel.hibernate.emailtemplate.EmailTemplate */ update
EmailTemplate
set
email_name=?,
html_Text=?,
plain_Text=?
where
template_id=?

Here is the getter:

Clob getHtmlTextClob() {
//1-
//return Hibernate.createClob(htmlText != null ? htmlText : " ");
//2-
return htmlTextClob;
}
With 1- the update statement is generated
With 2- the update statement is not generated
Why?

Extract of the setter:

void setHtmlTextClob(Clob htmlTextClob) {
this.htmlTextClob = htmlTextClob;
try {
if (htmlTextClob != null) {
htmlText = HibernateUtil.getStringFromClob(htmlTextClob);
//htmlText = "samuel";
} else
htmlText = "";

} catch (SQLException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
}

I have also another more critical issue which seems tied to the previous:
If I write the following piece of test code instead of the one shown above:

Session ss = HibernateUtil.getSessionFactory().openSession();
//S_LOGGER.debug("Number of current Hibernate sessions: "+ HibernateUtil.getSessionFactory().getStatistics().getSessionOpenCount());

EmailTemplate et = (EmailTemplate) ss.load(EmailTemplate.class, new Long("299941536982302"));
S_LOGGER.debug(et.getName());

Thread.sleep(5000);
S_LOGGER.debug("BEFORE FLUSH");
ss.flush();
S_LOGGER.debug("AFTER FLUSH");

As you can see in this piece of code i do not manage transactions explicitly and in that case my 2 java threads generated update statements which never ended: there was a deadlock on the DB.

During the last test, If I still did not manage transactions explicitly but I modified the getter like that:
Clob getHtmlTextClob() {
return htmlTextClob;
}
Then neither update statements nor deadlock were generated.
I wrote this piece of test code to reproduce deadlock I was facing on my Jonas server.

Could you please help me to understand this behaviour?

Here is anextract of my hibernate.cfg.xml:

<property name="connection.url">jdbc:oracle:thin:@192.168.2.7:1521:tlorcl1</property>
<property name="connection.username">samuel</property>
<property name="connection.password">toluna</property>
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property>
<property name="hibernate.use_sql_comments">true</property>
<property name="myeclipse.connection.profile">QA</property>
<property name="current_session_context_class">thread</property>

Thanks in advance
Regards
Samuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.