-->
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.  [ 8 posts ] 
Author Message
 Post subject: don't flush the Session after an exception occurs
PostPosted: Thu Apr 03, 2008 11:30 pm 
Newbie

Joined: Thu Apr 03, 2008 11:12 pm
Posts: 3
Code:
null id in com.blog.domain.Comment entry (don't flush the Session after an exception occurs)


hi

I need your help.thanks.

I have a application in remote server.
some time,my website happened an exception as following:
Code:
null id in com.blog.domain.Comment entry (don't flush the Session after an exception occurs)


I don't know how to resolve it.

my mapping config file:
Code:
<class name="com.blog.domain.Comment" table="comment" catalog="jiangzubing">
        <id name="id" type="java.lang.Integer">
            <column name="Id" />
            <generator class="native" />
        </id>
        <property name="articleid" type="java.lang.String">
            <column name="articleid" length="20" not-null="true" />
        </property>
        <property name="articletitle" type="java.lang.String">
            <column name="articletitle" length="100" not-null="true" />
        </property>
        <property name="content" type="java.lang.String">
            <column name="content" length="2000" not-null="true" />
        </property>
        <property name="user" type="java.lang.String">
            <column name="user" length="20" not-null="true" />
        </property>
        <property name="time" type="java.lang.String">
            <column name="time" length="20" not-null="true" />
        </property>
        <property name="isdelete" type="java.lang.Integer">
            <column name="isdelete" not-null="true" />
        </property>
    </class>


I used mysql database.and I never operation ID.
can you help me ?

if you understand my meaning and have a good idea,pls send it to

me.ok?thanks a lot.

my email address:jiangzubing@yahoo.cn

MSN:xiaoliu52013@163.com
[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 04, 2008 6:10 am 
Senior
Senior

Joined: Mon Feb 25, 2008 1:48 am
Posts: 191
Location: India
Can you post your complete stack trace and the java code that does the save operation?

_________________
Sukirtha


Top
 Profile  
 
 Post subject: Re: don't flush the Session after an exception occurs
PostPosted: Fri Apr 04, 2008 7:55 am 
Newbie

Joined: Thu Apr 03, 2008 11:12 pm
Posts: 3
hi
First.thanks your reply.
in fact,in my source are very simple.
I use session.save() or update().
only this.

by the way,in my log file I found:

[2008-04-04 10:14:29,187 TP-Processor3 AssertionFailure.java org.hibernate.AssertionFailure.<init>(AssertionFailure.java:22) ERROR - an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session)org.hibernate.AssertionFailure: null id in com.blog.domain.Comment entry (don't flush the Session after an exception occurs) at org.hibernate.event.def.DefaultFlushEntityEventListener.checkId(DefaultFlushEntityEventListener.java:48)[/code]


Top
 Profile  
 
 Post subject: Re: don't flush the Session after an exception occurs
PostPosted: Fri Apr 04, 2008 10:47 pm 
Newbie

Joined: Thu Apr 03, 2008 11:12 pm
Posts: 3
Who can help me?
thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 07, 2008 8:26 am 
Newbie

Joined: Tue Jan 22, 2008 5:51 pm
Posts: 7
Location: Brazil
the key column from your table is autoincrement ?
if true, try use generator class="identity" on id tag!

cya, good luck!


Top
 Profile  
 
 Post subject: Re: don't flush the Session after an exception occurs
PostPosted: Wed Mar 03, 2010 7:23 am 
Newbie

Joined: Wed Mar 03, 2010 6:28 am
Posts: 4
I have the same problem, but (strange to me) is that the problem only started occuring after changing our data source from local-tx to xa.

Using hibernate entity manager, I have the following

Code:
@Stateful
public class MyStatefulBean implements MyStateful {

  @In
  private User user;

  @EJB
  private LoggerBean loggerBean;
 
  public void eventOccurred() {
     if (user == null) { return; }
     loggerBean.log(new MyEntity(user.getUserId(), "Description"));
  }
}


The LoggerBean is stateless and has a log method that persists the entity (as initialized above) with entityManager.persist(theEntity)

The entity MyEntity has an Integer @Id with @GeneratedValue(strategy = GenerationType.IDENTITY) and the database uses an auto increment on the field, and a userId which is not nullable.

The exception is thrown because the userId is null at the time of the persist call.

Any ideas why this occurs when using an xa datasource?


Top
 Profile  
 
 Post subject: Re: don't flush the Session after an exception occurs
PostPosted: Thu Jun 24, 2010 4:13 am 
Newbie

Joined: Thu Jun 24, 2010 4:11 am
Posts: 1
It happened in my application where there is a duplicate key.
Check first the constraints before saving


EDIT
There are instances that the user (or yourself) clicked the button (that triggers the insert/update) twice. Also check on that part


Top
 Profile  
 
 Post subject: Re: don't flush the Session after an exception occurs
PostPosted: Thu Jun 24, 2010 5:52 am 
Newbie

Joined: Thu Jun 24, 2010 5:35 am
Posts: 1
brettcave wrote:
I have the same problem, but (strange to me) is that the problem only started occuring after changing our data source from local-tx to xa.

Using hibernate entity manager, I have the following

Code:
@Stateful
public class MyStatefulBean implements MyStateful {

  @In
  private User user;

  @EJB
  private LoggerBean loggerBean;
 
  public void eventOccurred() {
     if (user == null) { return; }
     loggerBean.log(new MyEntity(user.getUserId(), "Description"));
  }
}


The LoggerBean is stateless and has a log method that persists the entity (as initialized above) with entityManager.persist(theEntity)

The entity MyEntity has an Integer @Id with @GeneratedValue(strategy = GenerationType.IDENTITY) and the database uses an auto increment on the field, and a userId which is not nullable.

The exception is thrown because the userId is null at the time of the persist call.

Any ideas why this occurs when using an xa datasource?

Thanks you for the post.


__________________
Watch Grown Ups Online Free


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.